forked from qt-creator/qt-creator
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:
committed by
David Schulz
parent
57042da683
commit
a823caa396
@@ -108,6 +108,11 @@ public:
|
|||||||
return m_size == 0;
|
return m_size == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fillWithZero()
|
||||||
|
{
|
||||||
|
std::array<T, MaxSize>::fill(T(0));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::uint8_t m_size = 0;
|
std::uint8_t m_size = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ TextEditor::TextStyle toTextStyle(ClangBackEnd::HighlightingType type)
|
|||||||
TextEditor::TextStyles toTextStyles(ClangBackEnd::HighlightingTypes types)
|
TextEditor::TextStyles toTextStyles(ClangBackEnd::HighlightingTypes types)
|
||||||
{
|
{
|
||||||
TextEditor::TextStyles textStyles;
|
TextEditor::TextStyles textStyles;
|
||||||
|
textStyles.mixinStyles.fillWithZero();
|
||||||
|
|
||||||
textStyles.mainStyle = toTextStyle(types.mainHighlightingType);
|
textStyles.mainStyle = toTextStyle(types.mainHighlightingType);
|
||||||
|
|
||||||
|
|||||||
@@ -181,12 +181,9 @@ QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const
|
|||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint qHash(const TextStyles &textStyles)
|
uint qHash(TextStyles textStyles)
|
||||||
{
|
{
|
||||||
uint hash = qHash(textStyles.mainStyle);
|
return ::qHash(reinterpret_cast<quint64&>(textStyles));
|
||||||
for (TextStyle mixinStyle : textStyles.mixinStyles)
|
|
||||||
hash ^= qHash(mixinStyle);
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const TextStyles &first, const TextStyles &second)
|
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);
|
auto textCharFormatIterator = m_textCharFormatCache.find(textStyles);
|
||||||
if (textCharFormatIterator != m_textCharFormatCache.end())
|
if (textCharFormatIterator != m_textCharFormatCache.end())
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
|
|
||||||
QVector<QTextCharFormat> toTextCharFormats(const QVector<TextStyle> &categories) const;
|
QVector<QTextCharFormat> toTextCharFormats(const QVector<TextStyle> &categories) const;
|
||||||
QTextCharFormat toTextCharFormat(TextStyle category) const;
|
QTextCharFormat toTextCharFormat(TextStyle category) const;
|
||||||
QTextCharFormat toTextCharFormat(const TextStyles &textStyles) const;
|
QTextCharFormat toTextCharFormat(TextStyles textStyles) const;
|
||||||
|
|
||||||
QString family() const;
|
QString family() const;
|
||||||
void setFamily(const QString &family);
|
void setFamily(const QString &family);
|
||||||
|
|||||||
Reference in New Issue
Block a user