okular: 5-MOAD scan; okular-0001 CWE-407 fontReadingGotFont QList::indexOf O(F^2), 15.5x at F=1000
This commit is contained in:
parent
094c19c745
commit
68245c1ba8
4 changed files with 210 additions and 1 deletions
34
defects/okular-0001/patch/okular-0001.patch
Normal file
34
defects/okular-0001/patch/okular-0001.patch
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
--- a/core/document_p.h
|
||||
+++ b/core/document_p.h
|
||||
@@ -334,6 +334,7 @@ public:
|
||||
QPointer<FontExtractionThread> m_fontThread;
|
||||
bool m_fontsCached;
|
||||
QSet<DocumentInfo::Key> m_documentInfoAskedKeys;
|
||||
DocumentInfo m_documentInfo;
|
||||
FontInfo::List m_fontsCache;
|
||||
+ QSet<QString> m_fontsCacheKeys; // O(1) dedup set parallel to m_fontsCache
|
||||
|
||||
QSet<View *> m_views;
|
||||
|
||||
--- a/core/document.cpp
|
||||
+++ b/core/document.cpp
|
||||
@@ -1562,9 +1562,16 @@ void DocumentPrivate::fontReadingGotFont(const Okular::FontInfo &font)
|
||||
{
|
||||
- // Try to avoid duplicate fonts
|
||||
- if (m_fontsCache.indexOf(font) == -1) {
|
||||
+ // Try to avoid duplicate fonts — O(1) lookup via parallel key set
|
||||
+ // Previously: m_fontsCache.indexOf(font) which is O(F) per call, O(F^2) total.
|
||||
+ // Fix: build a composite key from all equality fields and use QSet for O(1) dedup.
|
||||
+ const QString key = font.name()
|
||||
+ + QLatin1Char('|') + font.substituteName()
|
||||
+ + QLatin1Char('|') + QString::number(static_cast<int>(font.type()))
|
||||
+ + QLatin1Char('|') + QString::number(static_cast<int>(font.embedType()))
|
||||
+ + QLatin1Char('|') + font.file()
|
||||
+ + QLatin1Char('|') + (font.canBeExtracted() ? QLatin1Char('1') : QLatin1Char('0'));
|
||||
+ if (!m_fontsCacheKeys.contains(key)) {
|
||||
+ m_fontsCacheKeys.insert(key);
|
||||
m_fontsCache.append(font);
|
||||
|
||||
Q_EMIT m_parent->gotFont(font);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue