a bit faster CompactHistoryType::scroll

wilder
Martin T. H. Sandsmark 5 years ago committed by Tomaz Canabrava
parent 167bdc64b9
commit a35991306c
  1. 1
      src/history/HistoryScroll.h
  2. 1
      src/history/HistoryScrollFile.h
  3. 4
      src/history/HistoryScrollNone.cpp
  4. 1
      src/history/HistoryScrollNone.h
  5. 14
      src/history/compact/CompactHistoryScroll.cpp
  6. 1
      src/history/compact/CompactHistoryScroll.h
  7. 7
      src/history/compact/CompactHistoryType.cpp

@ -43,6 +43,7 @@ public:
// adding lines. // adding lines.
virtual void addCells(const Character a[], const int count) = 0; 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 // convenience method - this is virtual so that subclasses can take advantage
// of QVector's implicit copying // of QVector's implicit copying
virtual void addCellsVector(const QVector<Character> &cells) virtual void addCellsVector(const QVector<Character> &cells)

@ -33,6 +33,7 @@ public:
LineProperty getLineProperty(const int lineno) const override; LineProperty getLineProperty(const int lineno) const override;
void addCells(const Character text[], const int count) 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; void addLine(LineProperty lineProperty = 0) override;
// Modify history // Modify history

@ -58,6 +58,10 @@ void HistoryScrollNone::addCells(const Character[], int)
{ {
} }
void HistoryScrollNone::addCellsMove(Character[], int)
{
}
void HistoryScrollNone::addLine(LineProperty) void HistoryScrollNone::addLine(LineProperty)
{ {
} }

@ -32,6 +32,7 @@ public:
LineProperty getLineProperty(const int lineno) const override; LineProperty getLineProperty(const int lineno) const override;
void addCells(const Character a[], const int count) 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 addLine(const LineProperty lineProperty = 0) override;
// Modify history (do nothing here) // 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) void CompactHistoryScroll::addLine(const LineProperty lineProperty)
{ {
auto &flag = _lineDatas.back().flag; auto &flag = _lineDatas.back().flag;

@ -30,6 +30,7 @@ public:
LineProperty getLineProperty(const int lineNumber) const override; LineProperty getLineProperty(const int lineNumber) const override;
void addCells(const Character a[], const int count) 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 addLine(const LineProperty lineProperty = 0) override;
void removeCells() override; void removeCells() override;

@ -40,12 +40,13 @@ void CompactHistoryType::scroll(std::unique_ptr<HistoryScroll> &old) const
Character line[LINE_SIZE]; Character line[LINE_SIZE];
int lines = (old != nullptr) ? old->getLines() : 0; int lines = (old != nullptr) ? old->getLines() : 0;
int i = qMax((lines - (int)_maxLines), 0); int i = qMax((lines - (int)_maxLines), 0);
std::vector<Character> tmp_line;
for (; i < lines; i++) { for (; i < lines; i++) {
int size = old->getLineLen(i); int size = old->getLineLen(i);
if (size > LINE_SIZE) { if (size > LINE_SIZE) {
auto tmp_line = std::make_unique<Character[]>(size); tmp_line.resize(size);
old->getCells(i, 0, size, tmp_line.get()); old->getCells(i, 0, size, tmp_line.data());
newScroll->addCells(tmp_line.get(), size); newScroll->addCellsMove(tmp_line.data(), size);
newScroll->addLine(old->getLineProperty(i)); newScroll->addLine(old->getLineProperty(i));
} else { } else {
old->getCells(i, 0, size, line); old->getCells(i, 0, size, line);

Loading…
Cancel
Save