Commit 27cedc46 authored by Carlos Alves's avatar Carlos Alves Committed by Kurt Hindenburg
Browse files

Change the content of HistoryLine using setCellsVectorAt

In compact history, instead of delete and add a new line, it will try
to change the line before delete and allocate memory.
parent 9d4df205
......@@ -91,6 +91,61 @@ void CompactHistoryLine::getCharacters(Character *array, int size, int startColu
}
}
void CompactHistoryLine::setCharacters(const TextLine &line)
{
if (line.isEmpty()) {
if (_formatArray) {
_blockListRef.deallocate(_formatArray);
}
if (_text) {
_blockListRef.deallocate(_text);
}
_formatArray = nullptr;
_text = nullptr;
_formatLength = 0;
_length = 0;
return;
}
int new_length = line.size();
// count number of different formats in this text line
Character c = line[0];
int new_formatLength = 1;
for (auto &k : line) {
if (!(k.equalsFormat(c))) {
new_formatLength++; // format change detected
c = k;
}
}
if (_formatLength < new_formatLength) {
_blockListRef.deallocate(_formatArray);
_formatArray = static_cast<CharacterFormat *>(_blockListRef.allocate(sizeof(CharacterFormat) * new_formatLength));
Q_ASSERT(_formatArray != nullptr);
}
if (_length < new_length) {
_blockListRef.deallocate(_text);
_text = static_cast<uint *>(_blockListRef.allocate(sizeof(uint) * new_length));
Q_ASSERT(_text != nullptr);
}
_length = new_length;
_formatLength = new_formatLength;
c = line[0];
_formatArray[0].setFormat(c);
_formatArray[0].startPos = 0;
for (int i = 0, k = 1; i < _length; i++) {
if (!line[i].equalsFormat(c)) {
c = line[i];
_formatArray[k].setFormat(c);
_formatArray[k].startPos = i;
k++;
}
_text[i] = line[i].character;
}
}
bool CompactHistoryLine::isWrapped() const
{
return _wrapped;
......
......@@ -27,6 +27,7 @@ public:
static void *operator new(size_t size, CompactHistoryBlockList &blockList);
static void operator delete(void *);
virtual void setCharacters(const TextLine &);
virtual void getCharacters(Character *array, int size, int startColumn);
virtual bool isWrapped() const;
virtual void setWrapped(bool value);
......
......@@ -129,10 +129,7 @@ void CompactHistoryScroll::setCellsAt(int position, const Character a[], int cou
void CompactHistoryScroll::setCellsVectorAt(int position, const TextLine &cells)
{
CompactHistoryLine *line = new (_blockList) CompactHistoryLine(cells, _blockList);
delete _lines.takeAt(position);
_lines.insert(position, line);
_lines[position]->setCharacters(cells);
}
void CompactHistoryScroll::setLineAt(int position, bool previousWrapped)
......
Markdown is supported
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