| .. | ||
| patch | ||
| test | ||
| README.md | ||
calligra-0001: KoShapeManager::addShape QList::contains O(N^2) dedup
Target: Calligra (libs/flake/KoShapeManager.cpp) MOAD: 0001 (CWE-407) Severity: MEDIUM Complexity: O(N^2) -> O(N) Measured speedup: 12.6x at N=5000
Location
libs/flake/KoShapeManager.cpp
KoShapeManager::addShape(), line 138
Defect
KoShapeManager::setShapes() iterates over all shapes and calls addShape()
for each. Inside addShape(), a membership guard uses QList::contains():
if (d->shapes.contains(shape)) // QList::contains is O(N)
return;
d->shapes.append(shape);
Since d->shapes is a QList<KoShape*> and the list grows with each call,
the i-th shape requires scanning i entries. Total cost for N shapes is O(N^2).
This affects document load, SVG import (SvgImport.cpp iterates shapes per layer), and image export (painter.setShapes(page->shapes()) called per page).
Fix
Change d->shapes and d->additionalShapes from QList<KoShape*> to
QSet<KoShape*>. QSet::contains and QSet::insert are O(1). Replace
removeAll with remove. The shapes() accessor returns d->shapes.values()
to preserve the QList<KoShape*> public API.
MOAD-0002 through 0005 (scan notes)
- MOAD-0002 (Intertangle): KoDocument/KoPADocument is a typical Qt document god object. No new coupling beyond expected KDE Frameworks patterns. CLEAN.
- MOAD-0003 (Leaked Context):
QThreadStorage<FastPathCacheItem*>inKoColorConversionCacheis a per-thread performance fast path for color space conversion, not request-scoped identity. CLEAN. - MOAD-0004 (CWE-312): Calligra Sidewinder filter logs
qCDebug(lcSidewinder) << "passwordHash=" << record->wPassword()wherewPassword()is the XLS 16-bit scrambled hash, not our plaintext password.qCDebugis a categorized Qt debug message compiled away in release or silenced unlessQT_LOGGING_RULES=*.debug=true. LOW severity. CLEAN. - MOAD-0005 (Thundering Herd): No unguarded concurrent cache patterns found. CLEAN.