diff --git a/src/buffer/katetextblock.h b/src/buffer/katetextblock.h --- a/src/buffer/katetextblock.h +++ b/src/buffer/katetextblock.h @@ -21,6 +21,8 @@ #ifndef KATE_TEXTBLOCK_H #define KATE_TEXTBLOCK_H +#include + #include #include @@ -206,7 +208,7 @@ */ void removeCursor(Kate::TextCursor *cursor) { - m_cursors.remove(cursor); + m_cursors.erase(cursor); } /** @@ -256,8 +258,9 @@ /** * Set of cursors for this block. + * We need no sharing, use STL. */ - QSet m_cursors; + std::unordered_set m_cursors; /** * Contains for each line-offset the ranges that were cached into it. diff --git a/src/buffer/katetextblock.cpp b/src/buffer/katetextblock.cpp --- a/src/buffer/katetextblock.cpp +++ b/src/buffer/katetextblock.cpp @@ -268,7 +268,7 @@ } // move cursors of the moved line from previous block to this block now - QSet newPreviousCursors; + std::unordered_set newPreviousCursors; for (TextCursor *cursor : qAsConst(previousBlock->m_cursors)) { if (cursor->lineInBlock() == lastLineOfPreviousBlock) { cursor->m_line = 0; @@ -543,7 +543,7 @@ m_lines.resize(fromLine); // move cursors - QSet oldBlockSet; + std::unordered_set oldBlockSet; for (TextCursor *cursor : qAsConst(m_cursors)) { if (cursor->lineInBlock() >= fromLine) { cursor->m_line = cursor->lineInBlock() - fromLine; @@ -596,7 +596,7 @@ void TextBlock::deleteBlockContent() { // kill cursors, if not belonging to a range - QSet copy = m_cursors; + std::unordered_set copy = m_cursors; for (TextCursor *cursor : qAsConst(copy)) { if (!cursor->kateRange()) { delete cursor; @@ -610,14 +610,20 @@ void TextBlock::clearBlockContent(TextBlock *targetBlock) { // move cursors, if not belonging to a range - QSet copy = m_cursors; - for (TextCursor *cursor : qAsConst(copy)) { + // we can do in-place editing of the current set of cursors + for (auto it = m_cursors.begin(); it != m_cursors.end();) { + auto cursor = *it; if (!cursor->kateRange()) { cursor->m_column = 0; cursor->m_line = 0; cursor->m_block = targetBlock; targetBlock->m_cursors.insert(cursor); - m_cursors.remove(cursor); + + // remove it and advance to next element + it = m_cursors.erase(it); + } else { + // keep this cursor + ++it; } }