Vixen
02b45cc4
csharp
public readonly record struct StyleSharingKey

What makes two elements able to share one ComputedStyle.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

⚠ The parent is the parent element, not the parent's computed style. [Doc 09](../../docs/plan/09-ui-framework.md) specifies the key as (tag, class set, inline style, parent computed style, pseudo state) and that is not sound. Two parents can hold the same computed style and still be told apart by a selector: given .a { color: red } and .b { color: red }, an .a and a .b intern to one identical style — and then .a .row { color: blue } matches one of their children and not the other's. Keyed on the parent style, both children share, and one of them is wrong.

Keyed on the parent element, sharing happens between siblings, and every descendant and child combinator is sound for free because the two elements have literally the same ancestor chain. This is what Gecko does and for this reason.

It is a narrower key, and the thing worth being clear about is what that does and does not cost. Interning is what gives every identical grid cell the same ComputedStyle reference, and it is unaffected: ten thousand cells across a thousand rows still hold one object, so the reference-compared invalidation doc 09 is really after still works. Sharing is what lets the cascade be skipped, and that now happens per row rather than per grid. Cheaper than being wrong.

What the key still cannot carry is where an element sits among its siblings, or what its attributes are — which is what SharingIsSound is for.

Fields and properties (7)

  • public StyleNodeId Parent

    The parent element. See the remarks — this is not what doc 09 says.

  • public int Tag

    The element's interned tag name.

  • public int Id

    Its interned id, or None.

  • public int ClassHash

    An order-independent hash of its class list.

  • public int ClassCount

    How many classes it has, so a hash collision needs a second coincidence.

  • public ElementState State

    Its pseudo state.

  • public InlineStyleId? Inline

    A handle on its inline declarations.

Methods (1)

  • public StyleSharingKey(StyleNodeId Parent, int Tag, int Id, int ClassHash, int ClassCount, ElementState State, InlineStyleId? Inline)

    What makes two elements able to share one ComputedStyle.

Used by (1)

  • StyleResolverVixen.Ui.Styling