TextEditor: Improve speed of hash function for font settings

The size of the array is fixed so we can simply use the memory patter as
a hash value.

Change-Id: If86a58b111a07b2bd9cecc12a03d74b93a914159
Task-number: QTCREATORBUG-16419
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Marco Bubke
2016-06-09 14:49:19 +02:00
committed by David Schulz
parent 57042da683
commit a823caa396
4 changed files with 10 additions and 7 deletions

View File

@@ -108,6 +108,11 @@ public:
return m_size == 0;
}
void fillWithZero()
{
std::array<T, MaxSize>::fill(T(0));
}
private:
std::uint8_t m_size = 0;
};

View File

@@ -70,6 +70,7 @@ TextEditor::TextStyle toTextStyle(ClangBackEnd::HighlightingType type)
TextEditor::TextStyles toTextStyles(ClangBackEnd::HighlightingTypes types)
{
TextEditor::TextStyles textStyles;
textStyles.mixinStyles.fillWithZero();
textStyles.mainStyle = toTextStyle(types.mainHighlightingType);

View File

@@ -181,12 +181,9 @@ QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const
return tf;
}
uint qHash(const TextStyles &textStyles)
uint qHash(TextStyles textStyles)
{
uint hash = qHash(textStyles.mainStyle);
for (TextStyle mixinStyle : textStyles.mixinStyles)
hash ^= qHash(mixinStyle);
return hash;
return ::qHash(reinterpret_cast<quint64&>(textStyles));
}
bool operator==(const TextStyles &first, const TextStyles &second)
@@ -219,7 +216,7 @@ void FontSettings::addMixinStyle(QTextCharFormat &textCharFormat,
};
}
QTextCharFormat FontSettings::toTextCharFormat(const TextStyles &textStyles) const
QTextCharFormat FontSettings::toTextCharFormat(TextStyles textStyles) const
{
auto textCharFormatIterator = m_textCharFormatCache.find(textStyles);
if (textCharFormatIterator != m_textCharFormatCache.end())

View File

@@ -66,7 +66,7 @@ public:
QVector<QTextCharFormat> toTextCharFormats(const QVector<TextStyle> &categories) const;
QTextCharFormat toTextCharFormat(TextStyle category) const;
QTextCharFormat toTextCharFormat(const TextStyles &textStyles) const;
QTextCharFormat toTextCharFormat(TextStyles textStyles) const;
QString family() const;
void setFamily(const QString &family);