Bug 285160
| Summary: | Improve DOMStringList::contains() from O(n) to O(1) | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Karl Dubost <karlcow> |
| Component: | DOM | Assignee: | 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
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 | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Karl Dubost
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
<rdar://problem/142250869>
Alexsander Borges Damaceno
Pull request: https://github.com/WebKit/WebKit/pull/38526
EWS
Committed 289769@main (c430a96674ce): <https://commits.webkit.org/289769@main>
Reviewed commits have been landed. Closing PR #38526 and removing active labels.