mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-07-31 09:46:05 -04:00
Adds deduping to attribute names. This has two benefits. First, it results in fewer dupes/allocations. Second, it allows finding an attribute name by a single pointer comparison. Say we need to create an attribute attr1=val1 (from the parser or JS, doesn't matter). We: 1 - Lookup "attr1" in String.intern, it doesn't exist 2 - We lookup or create "attr1" in Frame._attribute_names Whether the name was found in String.intern, found in Frame._attribute_names or created in Frame._attribute_names, any attribute name "attr1" always points to the same value. Now say we want to lookup the value "attr1". We _could_ iterate the attribute list and do a string comparison on each attribute. OR, we could apply the same canonicalization to that input as we did when building the list. We can do this via a read-don't-create API. If it doesn't find it, than that attribute was never canonicalized and thus, cannot exist (early exit!). If it IS found, then we now have the pointer for "attr1" that all attributes with "attr1" use, so we can just do a pointer comparison. We also replace the name: []const u8, value: []const u8 with a packed representation (where len: u32, instead of u64) meaning every attribute entry saves an extra 8 bytes (on top of the 16 bytes saved by the previous commit)
25 KiB
25 KiB