CompactHistoryScroll: Remove _maxLineCount + 5 lines at a time

This allows us to not do too many removals and thus be a lot faster.
wilder
Waqar Ahmed 4 years ago committed by Tomaz Canabrava
parent 6496415a33
commit d37d3ac11f
  1. 2
      src/characters/Character.h
  2. 26
      src/history/compact/CompactHistoryScroll.cpp
  3. 2
      src/history/compact/CompactHistoryScroll.h

@ -170,6 +170,6 @@ constexpr bool Character::equalsFormat(const Character &other) const
return backgroundColor == other.backgroundColor && foregroundColor == other.foregroundColor && rendition == other.rendition; return backgroundColor == other.backgroundColor && foregroundColor == other.foregroundColor && rendition == other.rendition;
} }
} }
Q_DECLARE_TYPEINFO(Konsole::Character, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Konsole::Character, Q_MOVABLE_TYPE);
#endif // CHARACTER_H #endif // CHARACTER_H

@ -23,16 +23,16 @@ CompactHistoryScroll::CompactHistoryScroll(const unsigned int maxLineCount)
setMaxNbLines(maxLineCount); setMaxNbLines(maxLineCount);
} }
void CompactHistoryScroll::removeFirstLine() void CompactHistoryScroll::removeLinesFromTop(int lines)
{ {
if (_index.size() > 1) { if (_index.size() > 1) {
_flags.erase(_flags.begin()); _flags.erase(_flags.begin(), _flags.begin() + lines);
const int removing = _index.front(); const int removing = _index[lines - 1];
std::transform(_index.begin() + 1, _index.end(), _index.begin(), [removing](int i) { std::transform(_index.begin() + lines, _index.end(), _index.begin(), [removing](int i) {
return i - removing; return i - removing;
}); });
_index.pop_back(); _index.erase(_index.end() - lines, _index.end());
_cells.erase(_cells.begin(), _cells.begin() + removing); _cells.erase(_cells.begin(), _cells.begin() + removing);
} else { } else {
@ -49,8 +49,8 @@ void CompactHistoryScroll::addCells(const Character a[], const int count)
_index.push_back(_cells.size()); _index.push_back(_cells.size());
_flags.push_back(LINE_DEFAULT); _flags.push_back(LINE_DEFAULT);
if (_index.size() > _maxLineCount) { if (_index.size() > _maxLineCount + 5) {
removeFirstLine(); removeLinesFromTop(5);
} }
} }
@ -99,8 +99,9 @@ void CompactHistoryScroll::setMaxNbLines(const int lineCount)
Q_ASSERT(lineCount >= 0); Q_ASSERT(lineCount >= 0);
_maxLineCount = lineCount; _maxLineCount = lineCount;
while (_index.size() > _maxLineCount) { if (_index.size() > _maxLineCount) {
removeFirstLine(); int linesToRemove = _index.size() - _maxLineCount;
removeLinesFromTop(linesToRemove);
} }
} }
@ -166,9 +167,10 @@ int CompactHistoryScroll::reflowLines(const int columns)
_flags = std::move(newLine.flags); _flags = std::move(newLine.flags);
int deletedLines = 0; int deletedLines = 0;
while ((size_t)getLines() > _maxLineCount) { size_t totalLines = getLines();
removeFirstLine(); if (totalLines > _maxLineCount) {
++deletedLines; deletedLines = totalLines - _maxLineCount;
removeLinesFromTop(deletedLines);
} }
return deletedLines; return deletedLines;

@ -45,7 +45,7 @@ private:
size_t _maxLineCount; size_t _maxLineCount;
void removeFirstLine(); void removeLinesFromTop(int lines);
inline int lineLen(const int line) const inline int lineLen(const int line) const
{ {

Loading…
Cancel
Save