From 4cc9c9997e5d9f190a5cfaa28ea1aac0fae34b4b Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 16 May 2018 20:41:02 +1000 Subject: [PATCH] compute_line_modifications: avoid potentially long iteration --- src/line_modification.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/line_modification.cc b/src/line_modification.cc index df2b9cbc..da3ee87f 100644 --- a/src/line_modification.cc +++ b/src/line_modification.cc @@ -73,10 +73,13 @@ Vector compute_line_modifications(const Buffer& buffer, size_t } next = res.erase(next, delend); - for (auto it = next; it != res.end(); ++it) - it->new_line -= diff; + if (diff != 0) + { + for (auto it = next; it != res.end(); ++it) + it->new_line -= diff; + } } - else + else if (diff != 0) { for (auto it = next; it != res.end(); ++it) it->new_line += diff;