Bug 285160

Summary: Improve DOMStringList::contains() from O(n) to O(1)
Product: WebKit Reporter: Karl Dubost <karlcow>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, webkit-bug-importer
Priority: P2 Keywords: GoodFirstBug, InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Karl Dubost
Reported 2024-12-25 20:40:18 PST
https://searchfox.org/wubkat/rev/36d40c7dfd972e688c9c0febea6821825a85d6ac/Source/WebCore/dom/DOMStringList.cpp#38-48 ```cpp bool DOMStringList::contains(const String& string) const { // FIXME: Currently, all consumers of DOMStringList store fairly small lists and thus an O(n) // algorithm is OK. But this may need to be optimized if larger amounts of data are // stored in m_strings. for (auto& value : m_strings) { if (value == string) return true; } return false; } ```
Attachments
Karl Dubost
Comment 1 2024-12-25 20:44:59 PST
It should be possible to initialize an unordered_string with all the strings and making it private. if (!m_stringSet) { m_stringSet.emplace(m_strings.begin(), m_strings.end()); } Then the contains function could return a result with m_stringSet->find(string) != m_stringSet->end();
Radar WebKit Bug Importer
Comment 2 2025-01-01 20:41:13 PST
Alexsander Borges Damaceno
Comment 3 2025-01-03 20:56:26 PST
EWS
Comment 4 2025-02-03 22:43:19 PST
Committed 289769@main (c430a96674ce): <https://commits.webkit.org/289769@main> Reviewed commits have been landed. Closing PR #38526 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.