Commit a3599130 authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark Committed by Tomaz Canabrava
Browse files

a bit faster CompactHistoryType::scroll

parent 167bdc64
Pipeline #179898 passed with stage
in 19 minutes and 7 seconds
......@@ -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<Character> &cells)
......
......@@ -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
......
......@@ -58,6 +58,10 @@ void HistoryScrollNone::addCells(const Character[], int)
{
}
void HistoryScrollNone::addCellsMove(Character[], int)
{
}
void HistoryScrollNone::addLine(LineProperty)
{
}
......
......@@ -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)
......
......@@ -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<unsigned int>(_cells.size() + _indexBias), LINE_DEFAULT});
if (_lineDatas.size() > _maxLineCount + 5) {
removeLinesFromTop(5);
}
}
void CompactHistoryScroll::addLine(const LineProperty lineProperty)
{
auto &flag = _lineDatas.back().flag;
......
......@@ -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;
......
......@@ -40,12 +40,13 @@ void CompactHistoryType::scroll(std::unique_ptr<HistoryScroll> &old) const
Character line[LINE_SIZE];
int lines = (old != nullptr) ? old->getLines() : 0;
int i = qMax((lines - (int)_maxLines), 0);
std::vector<Character> tmp_line;
for (; i < lines; i++) {
int size = old->getLineLen(i);
if (size > LINE_SIZE) {
auto tmp_line = std::make_unique<Character[]>(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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment