diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-12-17 21:50:08 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-12-17 22:08:58 +0100 |
| commit | 13f395f20bd786d6c055b59ad19e9018d85bc139 (patch) | |
| tree | 83d4688869228fb05fdafadbce3762980d783cb4 /src/css/stylednode.nim | |
| parent | cca92e2646d6decb59aa473aece834a81511cb3a (diff) | |
| download | chawan-13f395f20bd786d6c055b59ad19e9018d85bc139.tar.gz | |
match: optimize dependency tracking
This is a bit tricky, but it seems to work. It optimizes selectors in
the line of "div :hover" (note the space.)
Previously such selectors would add a hover dependency to pretty much
every element, and trigger a re-style for all elements that changed
their hover status. After this patch, when :hover and friends would
return false, they first try to match the element *without* pseudo
selectors, and only add their dependencies if the element would match
like that.
(Notably, it only does this for when :hover is false. Probably it would
help somewhat if we checked for the opposite with true too, but I'm not
sure how much.
For now, I'll keep it like this, and maybe try to further optimize it
later.)
Diffstat (limited to 'src/css/stylednode.nim')
| -rw-r--r-- | src/css/stylednode.nim | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/css/stylednode.nim b/src/css/stylednode.nim index 5e060142..46df5ff0 100644 --- a/src/css/stylednode.nim +++ b/src/css/stylednode.nim @@ -94,9 +94,12 @@ proc isValid*(styledNode: StyledNode; toReset: var seq[Element]): bool = return true proc add*(depends: var DependencyInfo; element: Element; t: DependencyType) = - let it = DependencyInfoItem(t: t, element: element) - if it notin depends.items: - depends.items.add(it) + depends.items.add(DependencyInfoItem(t: t, element: element)) + +proc merge*(a: var DependencyInfo; b: DependencyInfo) = + for it in b.items: + if it notin a.items: + a.items.add(it) func newStyledElement*(parent: StyledNode; element: Element): StyledNode = return StyledNode(t: stElement, node: element, parent: parent) |