Commit ff0681d4 authored by Carlos Alves's avatar Carlos Alves Committed by Tomaz Canabrava
Browse files

Change _screenLines to QVector

It was a fixed size array, as a QVector it will change size faster
without the need of memory allocation.
parent 86a48693
......@@ -47,7 +47,7 @@ Screen::Screen(int lines, int columns):
_currentTerminalDisplay(nullptr),
_lines(lines),
_columns(columns),
_screenLines(new ImageLine[_lines + 1]),
_screenLines(_lines + 1),
_screenLinesSize(_lines),
_scrolledLines(0),
_lastScrolledRegion(QRect()),
......@@ -86,7 +86,6 @@ Screen::Screen(int lines, int columns):
Screen::~Screen()
{
delete[] _screenLines;
delete _history;
delete _escapeSequenceUrlExtractor;
}
......@@ -391,56 +390,43 @@ void Screen::resizeImage(int new_lines, int new_columns)
CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_BACK_COLOR),
DEFAULT_RENDITION,
false);
QVector<ImageLine> images;
// First copy everything.
for (int i = 0; i < qMin(_lines, new_lines + 1) ; i++) {
// if the line have the 'NextLine' char, concat with the next line before push_back.
if (_screenLines[i].count() && _screenLines[i].at(_screenLines[i].count() - 1) == NextLine) {
_screenLines[i].pop_back();
_screenLines[i].append(_screenLines[i + 1]);
_screenLines[i + 1] = _screenLines[i];
// First join everything.
int currentPos = 0;
while (currentPos != _screenLines.count()) {
// if the line have the 'NextLine' char, concat with the next line and remove it.
if (_screenLines[currentPos].count() && _screenLines[currentPos].at(_screenLines[currentPos].count() - 1) == NextLine) {
_screenLines[currentPos].pop_back(); // remove 'NextLine'
_screenLines[currentPos].append(_screenLines[currentPos + 1]);
_screenLines.remove(currentPos + 1);
_cuY--;
continue;
}
images.push_back(_screenLines[i]);
currentPos++;
}
// Then move the data to lines below.
int currentPos = 0;
while (currentPos != images.count()) {
const bool shouldCopy = images[currentPos].size() > new_columns;
currentPos = 0;
while (currentPos != _screenLines.count()) {
const bool shouldCopy = _screenLines[currentPos].size() > new_columns;
// Copy from the current line, to the next one.
if (shouldCopy) {
// If we are in the last line, append a new one.
if (currentPos == images.count() - 1) {
images.append(ImageLine{});
if (currentPos == _screenLines.count() - 1) {
_screenLines.append(ImageLine{});
}
auto values = images[currentPos].mid(new_columns);
images[currentPos].remove(new_columns, values.size());
images[currentPos].append(NextLine);
images.insert(currentPos + 1, values);
_cuY++;
auto values = _screenLines[currentPos].mid(new_columns);
_screenLines[currentPos].remove(new_columns, values.size());
_screenLines[currentPos].append(NextLine);
_screenLines.insert(currentPos + 1, values);
}
currentPos += 1;
}
// Now set the correct image based on the moved lines.
auto newScreenLines = new ImageLine[new_lines + 1];
for (int i = 0; i < qMin(images.count(), new_lines + 1) ; i++) {
newScreenLines[i] = images[i];
}
delete[] _screenLines;
_screenLines = newScreenLines;
_screenLines.resize(new_lines + 1);
} else {
auto newScreenLines = new ImageLine[new_lines + 1];
for (int i = 0; i < qMin(_lines, new_lines + 1) ; i++) {
newScreenLines[i] = _screenLines[i];
}
delete[] _screenLines;
_screenLines = newScreenLines;
_screenLines.resize(new_lines + 1);
}
clearSelection();
......@@ -1437,7 +1423,7 @@ int Screen::copyLineToStream(int line ,
screenLine = qMin(screenLine, _screenLinesSize);
Character* data = _screenLines[screenLine].data();
auto* data = _screenLines[screenLine].data();
int length = _screenLines[screenLine].count();
// Don't remove end spaces in lines that wrap
......
......@@ -653,7 +653,7 @@ private:
int _columns;
typedef QVector<Character> ImageLine; // [0..columns]
ImageLine *_screenLines; // [lines]
QVector<ImageLine> _screenLines; // [lines]
int _screenLinesSize; // _screenLines.size()
int _scrolledLines;
......
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