Skip to content

[cssom] "Serialize a CSS declaration block" does redundant work collecting longhands #12193

@AtkinsSJ

Description

@AtkinsSJ

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 in declaration block’s declarations that that are not in already serialized and have a 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:

  1. Append all CSS declarations in longhands that have a 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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions