diff options
author | bptato <nincsnevem662@gmail.com> | 2024-05-28 01:02:08 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-05-28 01:02:08 +0200 |
commit | 03bbf7f451a638e2d1b4dff7ef659d70d576ff01 (patch) | |
tree | d2089990264d62c531d93cdc603418a73c9d4a53 /src/css | |
parent | 6340e6a2c041abb9273241897c485aabe87ff5dd (diff) | |
download | chawan-03bbf7f451a638e2d1b4dff7ef659d70d576ff01.tar.gz |
stylednode: remove `text' field
This avoids some unnecessary string copying.
Diffstat (limited to 'src/css')
-rw-r--r-- | src/css/cascade.nim | 10 | ||||
-rw-r--r-- | src/css/stylednode.nim | 12 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim index ab8e52de..cd80fb96 100644 --- a/src/css/cascade.nim +++ b/src/css/cascade.nim @@ -365,16 +365,18 @@ proc applyRulesFrameInvalid(frame: CascadeFrame; ua, user: CSSStylesheet; styledPseudo.children.add(styledPseudo.newStyledReplacement(content)) styledParent.children.add(styledPseudo) of peInputText: - let content = HTMLInputElement(styledParent.node).inputString() - if content.len > 0: + let s = HTMLInputElement(styledParent.node).inputString() + if s.len > 0: + let content = styledParent.node.document.newText(s) let styledText = styledParent.newStyledText(content) # Note: some pseudo-elements (like input text) generate text nodes # directly, so we have to cache them like this. styledText.pseudo = pseudo styledParent.children.add(styledText) of peTextareaText: - let content = HTMLTextAreaElement(styledParent.node).textAreaString() - if content.len > 0: + let s = HTMLTextAreaElement(styledParent.node).textAreaString() + if s.len > 0: + let content = styledParent.node.document.newText(s) let styledText = styledParent.newStyledText(content) styledText.pseudo = pseudo styledParent.children.add(styledText) diff --git a/src/css/stylednode.nim b/src/css/stylednode.nim index 4d14123d..0cfc8c64 100644 --- a/src/css/stylednode.nim +++ b/src/css/stylednode.nim @@ -47,7 +47,7 @@ type pseudo*: PseudoElem case t*: StyledType of stText: - text*: string + discard of stElement: computed*: CSSComputedValues children*: seq[StyledNode] @@ -57,13 +57,16 @@ type # replaced elements: quotes, or (TODO) markers, images content*: CSSContent +func textData*(styledNode: StyledNode): string = + return Text(styledNode.node).data + # For debugging func `$`*(node: StyledNode): string = if node == nil: return "nil" case node.t of stText: - return "#text " & node.text + return "#text " & node.textData of stElement: if node.node != nil: return $node.node @@ -181,11 +184,8 @@ func newStyledElement*(parent: StyledNode; pseudo: PseudoElem; parent: parent ) -func newStyledText*(parent: StyledNode; text: string): StyledNode = - return StyledNode(t: stText, text: text, parent: parent) - func newStyledText*(parent: StyledNode; text: Text): StyledNode = - return StyledNode(t: stText, text: text.data, node: text, parent: parent) + return StyledNode(t: stText, node: text, parent: parent) func newStyledReplacement*(parent: StyledNode; content: CSSContent): StyledNode = |