optimized VDOM implementation for uibench
This commit is contained in:
parent
91679f8ae6
commit
d3e1d28c89
1 changed files with 35 additions and 29 deletions
|
|
@ -106,6 +106,7 @@ type
|
||||||
# even index: key, odd index: value; done this way for memory efficiency:
|
# even index: key, odd index: value; done this way for memory efficiency:
|
||||||
attrs: seq[cstring]
|
attrs: seq[cstring]
|
||||||
events*: seq[(EventKind, EventHandler)]
|
events*: seq[(EventKind, EventHandler)]
|
||||||
|
when false:
|
||||||
hash*: Hash
|
hash*: Hash
|
||||||
validHash*: bool
|
validHash*: bool
|
||||||
dom*: Node ## the attached real DOM node. Can be 'nil' if the virtual node
|
dom*: Node ## the attached real DOM node. Can be 'nil' if the virtual node
|
||||||
|
|
@ -146,6 +147,10 @@ proc eq*(a, b: VNode): bool =
|
||||||
|
|
||||||
proc setAttr*(n: VNode; key: cstring; val: cstring = "") =
|
proc setAttr*(n: VNode; key: cstring; val: cstring = "") =
|
||||||
if n.attrs.isNil:
|
if n.attrs.isNil:
|
||||||
|
when true:
|
||||||
|
let x = @[key, val]
|
||||||
|
shallowCopy n.attrs, x
|
||||||
|
else:
|
||||||
n.attrs = @[key, val]
|
n.attrs = @[key, val]
|
||||||
else:
|
else:
|
||||||
for i in countup(0, n.attrs.len-2, 2):
|
for i in countup(0, n.attrs.len-2, 2):
|
||||||
|
|
@ -216,7 +221,8 @@ proc toString*(n: VNode; result: var string; indent: int) =
|
||||||
for i in 1..indent: result.add ' '
|
for i in 1..indent: result.add ' '
|
||||||
result.add "\L</" & $n.kind & ">"
|
result.add "\L</" & $n.kind & ">"
|
||||||
|
|
||||||
proc calcHash*(n: VNode) =
|
when false:
|
||||||
|
proc calcHash*(n: VNode) =
|
||||||
if n.validHash: return
|
if n.validHash: return
|
||||||
n.validHash = true
|
n.validHash = true
|
||||||
var h: Hash = ord n.kind
|
var h: Hash = ord n.kind
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue