Commit 81451bf
committed
LibWeb: Avoid O(n²) behavior in NamedNodeMap::supported_property_names
The function deduplicates attribute names in order. The previous
implementation used Vector::contains_slow() inside the loop, making the
overall complexity O(n²) in the number of attributes.
Replace the in-place linear search with a HashTable<FlyString> that
tracks which names have already been appended. Each set() call is O(1)
amortized, reducing the total deduplication step from O(n²) to O(n).
The pre-allocated hash table is initialised to the same capacity as
the attribute list so reallocation is avoided in the common case where
every attribute name is unique.
Fixes #7980.
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>1 parent de10db6 commit 81451bf
1 file changed
+7
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
58 | 64 | | |
59 | 65 | | |
60 | | - | |
| 66 | + | |
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
| |||
0 commit comments