aboutsummaryrefslogtreecommitdiffstats
path: root/src/css/cascade.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-12-03 18:42:12 +0100
committerbptato <nincsnevem662@gmail.com>2024-12-03 18:42:12 +0100
commit541828e3014f47730a49cd95cbd15f340cf8be07 (patch)
tree2a51925aea70af5218fa66c7d0cd31ccd3fb217d /src/css/cascade.nim
parent772b0a79e565a9c413766a0eb6b760d8d5cdd870 (diff)
downloadchawan-541828e3014f47730a49cd95cbd15f340cf8be07.tar.gz
cssvalues: optimize CSSComputedValues size
Roughly halves the object's size, and gets rid of a large number of allocations. It could be compressed further into a bitmap, but I'm not sure if it's worth the complexity.
Diffstat (limited to 'src/css/cascade.nim')
-rw-r--r--src/css/cascade.nim45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim
index f510d105..baccf8cd 100644
--- a/src/css/cascade.nim
+++ b/src/css/cascade.nim
@@ -174,7 +174,9 @@ func calcPresHints(element: Element): seq[CSSComputedEntry] =
if i <= 65534:
set_cv cptChaRowspan, integer, int(i)
template set_bgcolor_is_canvas =
- set_cv cptBgcolorIsCanvas, bgcolorIsCanvas, true
+ var val = CSSComputedValueBit()
+ val.bgcolorIsCanvas = true
+ result.add(makeEntry(cptBgcolorIsCanvas, val))
case element.tagType
of TAG_TABLE:
@@ -229,36 +231,43 @@ func buildComputedValues(rules: CSSValueEntryMap;
presHints: openArray[CSSComputedEntry]; parent: CSSComputedValues):
CSSComputedValues =
new(result)
+ var inited = default(array[CSSPropertyType, bool])
+ var uaInited = default(array[CSSPropertyType, bool])
+ var userInited = default(array[CSSPropertyType, bool])
for entry in rules[coUserAgent].normal: # user agent
- result.applyValue(entry, parent, nil)
+ result.applyValue(entry, parent, nil, inited)
+ inited[entry.t] = true
+ uaInited[entry.t] = true
+ userInited[entry.t] = true
let uaProperties = result.copyProperties()
# Presentational hints override user agent style, but respect user/author
# style.
for entry in presHints:
- result.applyValue(entry, nil, nil)
+ result.applyValue(entry, nil, nil, uaInited)
+ inited[entry.t] = true
+ userInited[entry.t] = true
for entry in rules[coUser].normal: # user
- result.applyValue(entry, parent, uaProperties)
+ result.applyValue(entry, parent, uaProperties, uaInited)
+ inited[entry.t] = true
+ userInited[entry.t] = true
# save user properties so author can use them
let userProperties = result.copyProperties()
for entry in rules[coAuthor].normal: # author
- result.applyValue(entry, parent, userProperties)
- # no need to save user origins
+ result.applyValue(entry, parent, userProperties, userInited)
+ inited[entry.t] = true
for entry in rules[coAuthor].important: # author important
- result.applyValue(entry, parent, userProperties)
- # important, so no need to save origins
+ result.applyValue(entry, parent, userProperties, userInited)
+ inited[entry.t] = true
for entry in rules[coUser].important: # user important
- result.applyValue(entry, parent, uaProperties)
- # important, so no need to save origins
+ result.applyValue(entry, parent, uaProperties, uaInited)
+ inited[entry.t] = true
for entry in rules[coUserAgent].important: # user agent important
- result.applyValue(entry, parent, nil)
- # important, so no need to save origins
+ result.applyValue(entry, parent, nil, uaInited)
+ inited[entry.t] = true
# set defaults
- for prop in CSSPropertyType:
- if result[prop] == nil:
- if prop.inherited and parent != nil:
- result[prop] = parent[prop]
- else:
- result[prop] = getDefault(prop)
+ for t in CSSPropertyType:
+ if not inited[t]:
+ result.initialOrInheritFrom(parent, t)
if result{"float"} != FloatNone:
#TODO it may be better to handle this in layout
let display = result{"display"}.blockify()