Skip to content

Commit

Permalink
QTextFormat: Use QMap::constFind() to avoid unnecessary detaches
Browse files Browse the repository at this point in the history
Use  QMap::constFind() instead of non-const QMap::find() where
applicable to avoid unnecessary detaches.

Change-Id: I76113c00efabb592f565f3ba4c90aefead1ac6a0
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
  • Loading branch information
VladimirBelyavsky committed Apr 21, 2024
1 parent b8d92d2 commit 3217c56
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/gui/text/qtextformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,26 +405,26 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextFormat &fmt
{
QMap<int, QVariant> properties = fmt.properties();
if (stream.version() < QDataStream::Qt_6_0) {
auto it = properties.find(QTextFormat::FontLetterSpacingType);
if (it != properties.end()) {
auto it = properties.constFind(QTextFormat::FontLetterSpacingType);
if (it != properties.cend()) {
properties[QTextFormat::OldFontLetterSpacingType] = it.value();
properties.erase(it);
}

it = properties.find(QTextFormat::FontStretch);
if (it != properties.end()) {
it = properties.constFind(QTextFormat::FontStretch);
if (it != properties.cend()) {
properties[QTextFormat::OldFontStretch] = it.value();
properties.erase(it);
}

it = properties.find(QTextFormat::TextUnderlineColor);
if (it != properties.end()) {
it = properties.constFind(QTextFormat::TextUnderlineColor);
if (it != properties.cend()) {
properties[QTextFormat::OldTextUnderlineColor] = it.value();
properties.erase(it);
}

it = properties.find(QTextFormat::FontFamilies);
if (it != properties.end()) {
it = properties.constFind(QTextFormat::FontFamilies);
if (it != properties.cend()) {
properties[QTextFormat::OldFontFamily] = QVariant(it.value().toStringList().constFirst());
properties.erase(it);
}
Expand Down

0 comments on commit 3217c56

Please sign in to comment.