From b1745ee8d353bdbe154666aadddccae87359dddf Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 7 Nov 2020 10:14:18 +1100 Subject: [PATCH] Fix performance issue when pasting many selection The previous code was advancing from the general insertion point for all selection, instead of iterating only once from insertion point until the end of inserted text. --- src/normal.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index bd520cb6..618c0008 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -748,12 +748,14 @@ void paste_all(Context& context, NormalParams params) Vector result; for (auto& ins_pos : insert_pos) { - ByteCount pos = 0; + ByteCount pos_offset = 0; + BufferCoord pos = ins_pos; for (auto offset : offsets) { - result.emplace_back(buffer.advance(ins_pos, pos), - buffer.advance(ins_pos, offset-1)); - pos = offset; + BufferCoord end = buffer.advance(pos, offset - pos_offset - 1); + result.emplace_back(pos, end); + pos = buffer.next(end); + pos_offset = offset; } } if (not result.empty())