diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index d05d9e5..1828da2 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -3034,12 +3034,11 @@ QTextFormatCollection::~QTextFormatCollection() int QTextFormatCollection::indexForFormat(const QTextFormat &format) { uint hash = format.d ? format.d->hash() : 0; - if (hashes.contains(hash)) { - for (int i = 0; i < formats.size(); ++i) { - if (formats.at(i) == format) - return i; - } + foreach (int i, hashes.values(hash)) { + if (formats.at(i) == format) + return i; } + int idx = formats.size(); formats.append(format); @@ -3048,8 +3047,7 @@ int QTextFormatCollection::indexForFormat(const QTextFormat &format) if (!f.d) f.d = new QTextFormatPrivate; f.d->resolveFont(defaultFnt); - - hashes.insert(hash); + hashes.insert(hash, idx); } QT_CATCH(...) { formats.pop_back(); @@ -3061,10 +3059,9 @@ int QTextFormatCollection::indexForFormat(const QTextFormat &format) bool QTextFormatCollection::hasFormatCached(const QTextFormat &format) const { uint hash = format.d ? format.d->hash() : 0; - if (hashes.contains(hash)) { - for (int i = 0; i < formats.size(); ++i) - if (formats.at(i) == format) - return true; + foreach (int i, hashes.values(hash)) { + if (formats.at(i) == format) + return true; } return false; } diff --git a/src/gui/text/qtextformat_p.h b/src/gui/text/qtextformat_p.h index c796343..73ca0ce 100644 --- a/src/gui/text/qtextformat_p.h +++ b/src/gui/text/qtextformat_p.h @@ -55,7 +55,7 @@ #include "QtGui/qtextformat.h" #include "QtCore/qvector.h" -#include "QtCore/qset.h" +#include "QtCore/qhash.h" QT_BEGIN_NAMESPACE @@ -97,7 +97,7 @@ public: FormatVector formats; QVector objFormats; - QSet hashes; + QMultiHash hashes; inline QFont defaultFont() const { return defaultFnt; } void setDefaultFont(const QFont &f);