Skip to content

Commit fe87905

Browse files
committed
Move arity and flat out to a role that we mix in on the handful of QAST nodes that need it. Shaves 16 bytes (on 64-bit) off the vast majority of nodes.
1 parent f0c85fd commit fe87905

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/QAST/Node.nqp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ class QAST::Node {
1515
has %!hash;
1616

1717
has $!node;
18-
has str $!named;
1918
has $!returns;
2019
has int $!arity;
21-
has int $!flat;
2220
has str $!childorder;
2321

2422
method new(*@children, *%options) {
@@ -31,11 +29,28 @@ class QAST::Node {
3129
}
3230

3331
method node(*@value) { $!node := @value[0] if @value; $!node }
34-
method named(*@value) { $!named := @value[0] if @value; $!named || "" }
3532
method returns(*@value) { $!returns := @value[0] if @value; $!returns }
36-
method arity(*@value) { $!arity := @value[0] if @value; $!arity }
37-
method flat(*@value) { $!flat := @value[0] if @value; $!flat }
3833
method childorder(*@value) { $!childorder := @value[0] if @value; $!childorder || "" }
34+
method arity(*@value) { $!arity := @value[0] if @value; $!arity }
35+
36+
method named(*@value) {
37+
if @value {
38+
self.HOW.mixin(self, QAST::SpecialArg);
39+
self.named(@value[0]);
40+
}
41+
else {
42+
""
43+
}
44+
}
45+
method flat(*@value) {
46+
if @value {
47+
self.HOW.mixin(self, QAST::SpecialArg);
48+
self.flat(@value[0]);
49+
}
50+
else {
51+
0
52+
}
53+
}
3954

4055
method list() { @!array }
4156
method pop() { nqp::pop(self.list) }

src/QAST/SpecialArg.nqp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
role QAST::SpecialArg {
2+
has str $!named;
3+
has int $!flat;
4+
5+
method named(*@value) { $!named := @value[0] if @value; $!named || "" }
6+
method flat(*@value) { $!flat := @value[0] if @value; $!flat }
7+
}

tools/build/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ QAST_PIR = QAST.pir
7070
QAST_PBC = QAST.pbc
7171
QAST_SOURCES = \
7272
src/QAST/CompileTimeValue.nqp \
73+
src/QAST/SpecialArg.nqp \
7374
src/QAST/Node.nqp \
7475
src/QAST/Regex.nqp \
7576
src/QAST/IVal.nqp \

0 commit comments

Comments
 (0)