Skip to content

Commit 78277ef

Browse files
committed
Optimize sections a bit to re-use the child renderer.
This should reduce any allocation overhead hopefully.
1 parent e6644f5 commit 78277ef

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

mustang/Node.ooc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import mustang/[Context, Value, Renderer, Template, Escape]
77
*/
88
TNode: abstract class {
99
next, firstChild: This
10+
childrenRenderer: Renderer
11+
12+
renderChildren: func(context: Context, out: Writer) {
13+
if(!childrenRenderer) {
14+
childrenRenderer = Renderer new(firstChild)
15+
}
16+
childrenRenderer render(context, out)
17+
}
1018

1119
render: abstract func(context: Context, out: Writer)
1220

@@ -78,12 +86,12 @@ SectionNode: class extends TNode {
7886
itemContext setValue("item", item)
7987
}
8088

81-
Renderer new(this firstChild) render(itemContext, out)
89+
renderChildren(itemContext, out)
8290
}
8391
}
8492
else if(variable instanceOf(BoolValue)) {
8593
if((variable as BoolValue) isTrue()) {
86-
Renderer new(this firstChild) render(context, out)
94+
renderChildren(context, out)
8795
}
8896
}
8997
else {

0 commit comments

Comments
 (0)