From a35991306c87d59cb14bfbb0ef9e76d441cc2c1f Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Mon, 20 Sep 2021 12:23:16 +0200 Subject: [PATCH] a bit faster CompactHistoryType::scroll --- src/history/HistoryScroll.h | 1 + src/history/HistoryScrollFile.h | 1 + src/history/HistoryScrollNone.cpp | 4 ++++ src/history/HistoryScrollNone.h | 1 + src/history/compact/CompactHistoryScroll.cpp | 14 ++++++++++++++ src/history/compact/CompactHistoryScroll.h | 1 + src/history/compact/CompactHistoryType.cpp | 7 ++++--- 7 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/history/HistoryScroll.h b/src/history/HistoryScroll.h index 82d53235..0f2901f2 100644 --- a/src/history/HistoryScroll.h +++ b/src/history/HistoryScroll.h @@ -43,6 +43,7 @@ public: // adding lines. virtual void addCells(const Character a[], const int count) = 0; + virtual void addCellsMove(Character a[], const int count) = 0; // convenience method - this is virtual so that subclasses can take advantage // of QVector's implicit copying virtual void addCellsVector(const QVector &cells) diff --git a/src/history/HistoryScrollFile.h b/src/history/HistoryScrollFile.h index 502a29cf..bb430656 100644 --- a/src/history/HistoryScrollFile.h +++ b/src/history/HistoryScrollFile.h @@ -33,6 +33,7 @@ public: LineProperty getLineProperty(const int lineno) const override; void addCells(const Character text[], const int count) override; + void addCellsMove(Character text[], const int count) override { addCells(text, count); } // TODO: optimize, if there's any point void addLine(LineProperty lineProperty = 0) override; // Modify history diff --git a/src/history/HistoryScrollNone.cpp b/src/history/HistoryScrollNone.cpp index b3e05df1..143ee702 100644 --- a/src/history/HistoryScrollNone.cpp +++ b/src/history/HistoryScrollNone.cpp @@ -58,6 +58,10 @@ void HistoryScrollNone::addCells(const Character[], int) { } +void HistoryScrollNone::addCellsMove(Character[], int) +{ +} + void HistoryScrollNone::addLine(LineProperty) { } diff --git a/src/history/HistoryScrollNone.h b/src/history/HistoryScrollNone.h index 34f8177a..6720e082 100644 --- a/src/history/HistoryScrollNone.h +++ b/src/history/HistoryScrollNone.h @@ -32,6 +32,7 @@ public: LineProperty getLineProperty(const int lineno) const override; void addCells(const Character a[], const int count) override; + void addCellsMove(Character a[], const int count) override; void addLine(const LineProperty lineProperty = 0) override; // Modify history (do nothing here) diff --git a/src/history/compact/CompactHistoryScroll.cpp b/src/history/compact/CompactHistoryScroll.cpp index 1de99cda..2a571b54 100644 --- a/src/history/compact/CompactHistoryScroll.cpp +++ b/src/history/compact/CompactHistoryScroll.cpp @@ -45,6 +45,20 @@ void CompactHistoryScroll::addCells(const Character a[], const int count) } } +void CompactHistoryScroll::addCellsMove(Character characters[], const int count) +{ + std::move(characters, characters + count, std::back_inserter(_cells)); + + // store the (biased) start of next line + default flag + // the flag is later updated when addLine is called + _lineDatas.push_back({static_cast(_cells.size() + _indexBias), LINE_DEFAULT}); + + if (_lineDatas.size() > _maxLineCount + 5) { + removeLinesFromTop(5); + } +} + + void CompactHistoryScroll::addLine(const LineProperty lineProperty) { auto &flag = _lineDatas.back().flag; diff --git a/src/history/compact/CompactHistoryScroll.h b/src/history/compact/CompactHistoryScroll.h index 85b789ab..c333bd74 100644 --- a/src/history/compact/CompactHistoryScroll.h +++ b/src/history/compact/CompactHistoryScroll.h @@ -30,6 +30,7 @@ public: LineProperty getLineProperty(const int lineNumber) const override; void addCells(const Character a[], const int count) override; + void addCellsMove(Character a[], const int count) override; void addLine(const LineProperty lineProperty = 0) override; void removeCells() override; diff --git a/src/history/compact/CompactHistoryType.cpp b/src/history/compact/CompactHistoryType.cpp index 8a85220f..37735340 100644 --- a/src/history/compact/CompactHistoryType.cpp +++ b/src/history/compact/CompactHistoryType.cpp @@ -40,12 +40,13 @@ void CompactHistoryType::scroll(std::unique_ptr &old) const Character line[LINE_SIZE]; int lines = (old != nullptr) ? old->getLines() : 0; int i = qMax((lines - (int)_maxLines), 0); + std::vector tmp_line; for (; i < lines; i++) { int size = old->getLineLen(i); if (size > LINE_SIZE) { - auto tmp_line = std::make_unique(size); - old->getCells(i, 0, size, tmp_line.get()); - newScroll->addCells(tmp_line.get(), size); + tmp_line.resize(size); + old->getCells(i, 0, size, tmp_line.data()); + newScroll->addCellsMove(tmp_line.data(), size); newScroll->addLine(old->getLineProperty(i)); } else { old->getCells(i, 0, size, line);