- From: Sam Atkins via GitHub <sysbot+gh@w3.org>
- Date: Wed, 14 May 2025 11:18:20 +0000
- To: public-css-archive@w3.org
AtkinsSJ has just created a new issue for https://github.com/w3c/csswg-drafts: == [cssom] "Serialize a CSS declaration block" does redundant work collecting longhands == Spun out from something I noticed in #12187: The "shorthand loop" of this algorithm does redundant work each loop iteration: > 1. Let `longhands` be an array consisting of all [CSS declarations](https://drafts.csswg.org/cssom/#css-declaration) in declaration block’s [declarations](https://drafts.csswg.org/cssom/#cssstyledeclaration-declarations) that that are not in already serialized and have a [property name](https://drafts.csswg.org/cssom/#css-declaration-property-name) that maps to one of the shorthand properties in shorthands. It's then only used to populate `current longhands` with a subset of its contents: > 4. Append all [CSS declarations](https://drafts.csswg.org/cssom/#css-declaration) in `longhands` that have a [property name](https://drafts.csswg.org/cssom/#css-declaration-property-name) that maps to shorthand to `current longhands`. (It's also used in step 2 to reject `shorthand` if it doesn't have what it needs - but that could easily use `current longhands` instead.) `longhands` itself doesn't serve any purpose as-is, it just is an extra array to allocate and add items to. I suspect the intention was as an optimization: If we only populate `longhands` once, *before* the loop, then it gives us a shorter list to iterate on each loop iteration, instead of having to look at every declaration each time. (I'm not convinced that would always be faster, fwiw, and it's unusual for a spec algorithm to attempt to optimize things.) Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/12193 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Wednesday, 14 May 2025 11:18:21 UTC