Commit 8c57c842 authored by Carlos Alves's avatar Carlos Alves Committed by Kurt Hindenburg
Browse files

Small changes to STL and qBound

Where it was possible:
- 'For' to STL copy or fill (it is like using memcpy and memset, faster
than for, the compiler decides the best algo to perform the task);
- qMin(qMax) to qBound.

Changes in: TeminalDisplay and TerminalColor
parent 8cf4601b
...@@ -53,9 +53,7 @@ namespace Konsole ...@@ -53,9 +53,7 @@ namespace Konsole
void TerminalColor::setColorTable(const QColor *table) void TerminalColor::setColorTable(const QColor *table)
{ {
for (int index = 0; index < TABLE_COLORS; index++) { std::copy(table, table + TABLE_COLORS, m_colorTable);
m_colorTable[index] = table[index];
}
setBackgroundColor(m_colorTable[DEFAULT_BACK_COLOR]); setBackgroundColor(m_colorTable[DEFAULT_BACK_COLOR]);
onColorsChanged(); onColorsChanged();
} }
......
...@@ -547,8 +547,8 @@ void TerminalDisplay::updateImage() ...@@ -547,8 +547,8 @@ void TerminalDisplay::updateImage()
CharacterColor cf; // undefined CharacterColor cf; // undefined
const int linesToUpdate = qMin(_lines, qMax(0, lines)); const int linesToUpdate = qBound(0, lines, _lines);
const int columnsToUpdate = qMin(_columns, qMax(0, columns)); const int columnsToUpdate = qBound(0, columns, _columns);
auto dirtyMask = new char[columnsToUpdate + 2]; auto dirtyMask = new char[columnsToUpdate + 2];
QRegion dirtyRegion; QRegion dirtyRegion;
...@@ -830,10 +830,10 @@ QRect TerminalDisplay::widgetToImage(const QRect &widgetArea) const ...@@ -830,10 +830,10 @@ QRect TerminalDisplay::widgetToImage(const QRect &widgetArea) const
QRect result; QRect result;
const int fontWidth = _terminalFont->fontWidth(); const int fontWidth = _terminalFont->fontWidth();
const int fontHeight = _terminalFont->fontHeight(); const int fontHeight = _terminalFont->fontHeight();
result.setLeft( qMin(_usedColumns - 1, qMax(0, (widgetArea.left() - contentsRect().left() - _contentRect.left()) / fontWidth ))); result.setLeft( qBound(0, (widgetArea.left() - contentsRect().left() - _contentRect.left()) / fontWidth, _usedColumns - 1));
result.setTop( qMin(_usedLines - 1, qMax(0, (widgetArea.top() - contentsRect().top() - _contentRect.top() ) / fontHeight))); result.setTop( qBound(0, (widgetArea.top() - contentsRect().top() - _contentRect.top() ) / fontHeight, _usedLines - 1));
result.setRight( qMin(_usedColumns - 1, qMax(0, (widgetArea.right() - contentsRect().left() - _contentRect.left()) / fontWidth ))); result.setRight( qBound(0, (widgetArea.right() - contentsRect().left() - _contentRect.left()) / fontWidth, _usedColumns - 1));
result.setBottom(qMin(_usedLines - 1, qMax(0, (widgetArea.bottom() - contentsRect().top() - _contentRect.top() ) / fontHeight))); result.setBottom(qBound(0, (widgetArea.bottom() - contentsRect().top() - _contentRect.top() ) / fontHeight, _usedLines - 1));
return result; return result;
} }
...@@ -1034,9 +1034,7 @@ void TerminalDisplay::makeImage() ...@@ -1034,9 +1034,7 @@ void TerminalDisplay::makeImage()
void TerminalDisplay::clearImage() void TerminalDisplay::clearImage()
{ {
for (int i = 0; i < _imageSize; ++i) { std::fill(_image, _image + _imageSize, Screen::DefaultChar);
_image[i] = Screen::DefaultChar;
}
} }
void TerminalDisplay::calcGeometry() void TerminalDisplay::calcGeometry()
...@@ -1165,16 +1163,14 @@ void TerminalDisplay::mousePressEvent(QMouseEvent* ev) ...@@ -1165,16 +1163,14 @@ void TerminalDisplay::mousePressEvent(QMouseEvent* ev)
} }
// Ignore clicks on the message widget // Ignore clicks on the message widget
if (_readOnlyMessageWidget != nullptr) { if (_readOnlyMessageWidget != nullptr &&
if (_readOnlyMessageWidget->isVisible() && _readOnlyMessageWidget->frameGeometry().contains(ev->pos())) { _readOnlyMessageWidget->isVisible() && _readOnlyMessageWidget->frameGeometry().contains(ev->pos())) {
return; return;
}
} }
if (_outputSuspendedMessageWidget != nullptr) { if (_outputSuspendedMessageWidget != nullptr &&
if (_outputSuspendedMessageWidget->isVisible() && _outputSuspendedMessageWidget->frameGeometry().contains(ev->pos())) { _outputSuspendedMessageWidget->isVisible() && _outputSuspendedMessageWidget->frameGeometry().contains(ev->pos())) {
return; return;
}
} }
auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !_usesMouseTracking); auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !_usesMouseTracking);
......
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