Improve clearImage performance

This commit is contained in:
Waqar Ahmed
2021-12-04 13:20:40 +05:00
parent f963807035
commit a629b45636
5 changed files with 47 additions and 31 deletions

View File

@@ -6,6 +6,7 @@
*/
#include "EscapeSequenceUrlExtractor.h"
#include "Screen.h"
#include <QUrl>
@@ -19,22 +20,13 @@ void Konsole::EscapeSequenceUrlExtractor::setScreen(Konsole::Screen *screen)
clear();
}
bool EscapeSequenceUrlExtractor::reading() const
{
return _reading;
}
void EscapeSequenceUrlExtractor::beginUrlInput()
{
_reading = true;
}
void EscapeSequenceUrlExtractor::appendUrlText(QChar c)
void EscapeSequenceUrlExtractor::appendUrlText_internal(QChar c)
{
if (!reading()) {
return;
}
if (_currentUrl.text.isEmpty()) {
// We need to on getCursorX because we want the position of the
// last printed character, not the cursor.

View File

@@ -8,7 +8,6 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "Screen.h"
#include <QObject>
#include <QPointer>
@@ -32,6 +31,8 @@ struct ExtractedUrl {
Coordinate end;
};
class Screen;
/* Stored in Screen, but used in V10Emulation to
* store extracted URL's. Perhaps this should be a Model?
*/
@@ -64,6 +65,8 @@ private:
/* Pointer to the Screen, that actually holds the text data. */
Screen *_screen;
void appendUrlText_internal(QChar c);
public:
/* This needs to have access to the Session
* calculate the row / col of the current URL.
@@ -78,7 +81,10 @@ public:
void setScreen(Screen *screen);
/* If we are parsing a URL */
bool reading() const;
bool reading() const
{
return _reading;
}
/* We found an URL, starting to parse */
void beginUrlInput();
@@ -90,8 +96,17 @@ public:
void abortUrlInput();
/* The URL is parsed at once, but not the text. We received
* one character per time until we hit the end byte. */
void appendUrlText(QChar c);
* one character per time until we hit the end byte.
*
* The function is splitted to help inlining when reading=false
*/
void appendUrlText(QChar c)
{
if (!reading()) {
return;
}
appendUrlText_internal(c);
}
/* The URL is parsed at once, store it at once. */
void setUrl(const QString &url);

View File

@@ -87,9 +87,8 @@ Screen::Screen(int lines, int columns)
, _effectiveRendition(DEFAULT_RENDITION)
, _lastPos(-1)
, _lastDrawnChar(0)
, _escapeSequenceUrlExtractor(std::make_unique<EscapeSequenceUrlExtractor>())
{
_escapeSequenceUrlExtractor->setScreen(this);
_escapeSequenceUrlExtractor.setScreen(this);
std::fill(_lineProperties.begin(), _lineProperties.end(), LINE_DEFAULT);
initTabStops();
@@ -478,7 +477,7 @@ void Screen::resizeImage(int new_lines, int new_columns)
// If _history size > max history size it will drop a line from _history.
// We need to verify if we need to remove a URL.
if (removedLines) {
_escapeSequenceUrlExtractor->historyLinesRemoved(removedLines);
_escapeSequenceUrlExtractor.historyLinesRemoved(removedLines);
}
}
@@ -1001,7 +1000,7 @@ void Screen::displayCharacter(uint c)
--w;
}
_cuX = newCursorX;
_escapeSequenceUrlExtractor->appendUrlText(QChar(c));
_escapeSequenceUrlExtractor.appendUrlText(QChar(c));
}
int Screen::scrolledLines() const
@@ -1154,7 +1153,12 @@ void Screen::clearImage(int loca, int loce, char c, bool resetLineRendition)
QVector<Character> &line = _screenLines[y];
if (isDefaultCh && endCol == _columns - 1) {
std::fill(line.begin() + startCol, line.end(), clearCh);
static std::vector<Character> cl(_columns, DefaultChar);
if (Q_UNLIKELY((int)cl.size() < _columns)) {
cl.resize(_columns, DefaultChar);
}
auto copyAmount = std::distance(line.begin() + startCol, line.end());
memcpy(line.data() + startCol, cl.data(), copyAmount * sizeof(Character));
} else {
if (line.size() < endCol + 1) {
line.resize(endCol + 1);
@@ -1639,7 +1643,7 @@ void Screen::fastAddHistLine()
// If _history size > max history size it will drop a line from _history.
// We need to verify if we need to remove a URL.
if (removeLine) {
_escapeSequenceUrlExtractor->historyLinesRemoved(1);
_escapeSequenceUrlExtractor.historyLinesRemoved(1);
}
// Rotate left + clear the last line
@@ -1670,7 +1674,7 @@ void Screen::addHistLine()
++_droppedLines;
// We removed a line, we need to verify if we need to remove a URL.
_escapeSequenceUrlExtractor->historyLinesRemoved(1);
_escapeSequenceUrlExtractor.historyLinesRemoved(1);
}
}
@@ -1763,7 +1767,7 @@ void Screen::fillWithDefaultChar(Character *dest, int count)
std::fill_n(dest, count, Screen::DefaultChar);
}
Konsole::EscapeSequenceUrlExtractor *Konsole::Screen::urlExtractor() const
Konsole::EscapeSequenceUrlExtractor *Konsole::Screen::urlExtractor()
{
return _escapeSequenceUrlExtractor.get();
return &_escapeSequenceUrlExtractor;
}

View File

@@ -20,6 +20,7 @@
// Konsole
#include "../characters/Character.h"
#include "EscapeSequenceUrlExtractor.h"
#include "konsoleprivate_export.h"
#define MODE_Origin 0
@@ -90,7 +91,7 @@ public:
Screen(const Screen &) = delete;
Screen &operator=(const Screen &) = delete;
EscapeSequenceUrlExtractor *urlExtractor() const;
EscapeSequenceUrlExtractor *urlExtractor();
// VT100/2 Operations
// Cursor Movement
@@ -771,7 +772,7 @@ private:
// used in REP (repeating char)
quint32 _lastDrawnChar;
std::unique_ptr<EscapeSequenceUrlExtractor> _escapeSequenceUrlExtractor;
EscapeSequenceUrlExtractor _escapeSequenceUrlExtractor;
void toggleUrlInput();
// Vt102Emulation defined max argument value that can be passed to a Screen function

View File

@@ -60,9 +60,14 @@ void TerminalPainter::drawContents(Character *image,
{
const auto display = qobject_cast<TerminalDisplay *>(sender());
QVector<uint> univec;
QVarLengthArray<uint> univec;
univec.reserve(display->usedColumns());
const auto displayLeft = display->contentsRect().left();
const auto displayTop = display->contentsRect().top();
int fontHeight = display->terminalFont()->fontHeight();
int fontWidth = display->terminalFont()->fontWidth();
for (int y = rect.y(); y <= rect.bottom(); y++) {
int x = rect.x();
bool doubleHeightLinePair = false;
@@ -185,11 +190,10 @@ void TerminalPainter::drawContents(Character *image,
paint.setWorldTransform(QTransform(textScale), true);
// Calculate the area in which the text will be drawn
QRect textArea =
QRect(display->contentRect().left() + display->contentsRect().left() + display->terminalFont()->fontWidth() * x * (doubleWidthLine ? 2 : 1),
display->contentRect().top() + display->contentsRect().top() + display->terminalFont()->fontHeight() * y,
display->terminalFont()->fontWidth() * len,
doubleHeight && !doubleHeightLinePair ? display->terminalFont()->fontHeight() / 2 : display->terminalFont()->fontHeight());
QRect textArea = QRect(display->contentRect().left() + displayLeft + fontWidth * x * (doubleWidthLine ? 2 : 1),
display->contentRect().top() + displayTop + fontHeight * y,
fontWidth * len,
doubleHeight && !doubleHeightLinePair ? fontHeight / 2 : fontHeight);
// move the calculated area to take account of scaling applied to the painter.
// the position of the area from the origin (0,0) is scaled