Filename | /var/www/foswikidev/core/lib/Foswiki/Infix/Node.pm |
Statements | Executed 2102 statements in 3.12ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.80ms | 3.08ms | BEGIN@131 | Foswiki::Infix::Node::
259 | 2 | 2 | 1.19ms | 1.19ms | newNode | Foswiki::Infix::Node::
147 | 2 | 1 | 735µs | 1.54ms | newLeaf | Foswiki::Infix::Node::
80 | 1 | 1 | 282µs | 282µs | convertToLeaf | Foswiki::Infix::Node::
1 | 1 | 1 | 13µs | 25µs | BEGIN@14 | Foswiki::Infix::Node::
1 | 1 | 1 | 11µs | 69µs | BEGIN@29 | Foswiki::Infix::Node::
1 | 1 | 1 | 9µs | 13µs | BEGIN@15 | Foswiki::Infix::Node::
1 | 1 | 1 | 9µs | 31µs | BEGIN@16 | Foswiki::Infix::Node::
1 | 1 | 1 | 9µs | 42µs | BEGIN@26 | Foswiki::Infix::Node::
1 | 1 | 1 | 4µs | 4µs | BEGIN@18 | Foswiki::Infix::Node::
0 | 0 | 0 | 0s | 0s | isLeaf | Foswiki::Infix::Node::
0 | 0 | 0 | 0s | 0s | stringify | Foswiki::Infix::Node::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | =begin TML | ||||
4 | |||||
5 | ---+ package Foswiki::Infix::Node | ||||
6 | |||||
7 | Base class for node types generated by Infix::Parser (and its subclasses). This | ||||
8 | defines the interface used to construct nodes from the parser. | ||||
9 | |||||
10 | =cut | ||||
11 | |||||
12 | package Foswiki::Infix::Node; | ||||
13 | |||||
14 | 2 | 36µs | 2 | 37µs | # spent 25µs (13+12) within Foswiki::Infix::Node::BEGIN@14 which was called:
# once (13µs+12µs) by Foswiki::Infix::Parser::BEGIN@26 at line 14 # spent 25µs making 1 call to Foswiki::Infix::Node::BEGIN@14
# spent 12µs making 1 call to strict::import |
15 | 2 | 25µs | 2 | 17µs | # spent 13µs (9+4) within Foswiki::Infix::Node::BEGIN@15 which was called:
# once (9µs+4µs) by Foswiki::Infix::Parser::BEGIN@26 at line 15 # spent 13µs making 1 call to Foswiki::Infix::Node::BEGIN@15
# spent 4µs making 1 call to warnings::import |
16 | 2 | 43µs | 2 | 54µs | # spent 31µs (9+22) within Foswiki::Infix::Node::BEGIN@16 which was called:
# once (9µs+22µs) by Foswiki::Infix::Parser::BEGIN@26 at line 16 # spent 31µs making 1 call to Foswiki::Infix::Node::BEGIN@16
# spent 22µs making 1 call to Exporter::import |
17 | |||||
18 | # spent 4µs within Foswiki::Infix::Node::BEGIN@18 which was called:
# once (4µs+0s) by Foswiki::Infix::Parser::BEGIN@26 at line 23 | ||||
19 | 1 | 9µs | if ( $Foswiki::cfg{UseLocale} ) { | ||
20 | require locale; | ||||
21 | import locale(); | ||||
22 | } | ||||
23 | 1 | 21µs | 1 | 4µs | } # spent 4µs making 1 call to Foswiki::Infix::Node::BEGIN@18 |
24 | |||||
25 | # 1 for debug | ||||
26 | 2 | 41µs | 2 | 76µs | # spent 42µs (9+34) within Foswiki::Infix::Node::BEGIN@26 which was called:
# once (9µs+34µs) by Foswiki::Infix::Parser::BEGIN@26 at line 26 # spent 42µs making 1 call to Foswiki::Infix::Node::BEGIN@26
# spent 34µs making 1 call to constant::import |
27 | |||||
28 | # Leaf token types | ||||
29 | # spent 69µs (11+58) within Foswiki::Infix::Node::BEGIN@29 which was called:
# once (11µs+58µs) by Foswiki::Infix::Parser::BEGIN@26 at line 35 | ||||
30 | 1 | 8µs | 1 | 58µs | NAME => 1, # spent 58µs making 1 call to constant::import |
31 | NUMBER => 2, | ||||
32 | STRING => 3, | ||||
33 | HASH => 4, | ||||
34 | META => 5, | ||||
35 | 1 | 320µs | 1 | 69µs | }; # spent 69µs making 1 call to Foswiki::Infix::Node::BEGIN@29 |
36 | |||||
37 | =begin TML | ||||
38 | |||||
39 | ---++ ClassMethod newNode( $o, @p ) -> \$if | ||||
40 | |||||
41 | Construct a new parse node (contract with Infix::Parser) | ||||
42 | |||||
43 | =cut | ||||
44 | |||||
45 | # spent 1.19ms within Foswiki::Infix::Node::newNode which was called 259 times, avg 5µs/call:
# 147 times (802µs+0s) by Foswiki::Infix::Node::newLeaf at line 66, avg 5µs/call
# 112 times (390µs+0s) by Foswiki::Infix::Parser::_apply at line 363 of /var/www/foswikidev/core/lib/Foswiki/Infix/Parser.pm, avg 3µs/call | ||||
46 | 259 | 77µs | my $class = shift; | ||
47 | 259 | 48µs | my $op = shift; | ||
48 | 259 | 277µs | my $this = bless( {}, $class ); | ||
49 | 259 | 351µs | @{ $this->{params} } = @_; | ||
50 | 259 | 112µs | $this->{op} = $op; | ||
51 | 259 | 702µs | return $this; | ||
52 | } | ||||
53 | |||||
54 | =begin TML | ||||
55 | |||||
56 | ---++ ClassMethod newLeaf( $val, $type ) -> \$if | ||||
57 | |||||
58 | Construct a new terminal node (contract with Infix::Parser) | ||||
59 | * =$val= - the (scalar) value of the leaf | ||||
60 | * =$type= - one of NAME, NUMBER, STRING | ||||
61 | |||||
62 | =cut | ||||
63 | |||||
64 | # spent 1.54ms (735µs+802µs) within Foswiki::Infix::Node::newLeaf which was called 147 times, avg 10µs/call:
# 144 times (719µs+787µs) by Foswiki::Query::Node::newLeaf at line 141 of /var/www/foswikidev/core/lib/Foswiki/Query/Node.pm, avg 10µs/call
# 3 times (16µs+16µs) by Foswiki::Query::Node::newLeaf at line 138 of /var/www/foswikidev/core/lib/Foswiki/Query/Node.pm, avg 10µs/call | ||||
65 | 147 | 105µs | my ( $class, $val, $type ) = @_; | ||
66 | 147 | 432µs | 147 | 802µs | return newNode( $class, $type, $val ); # spent 802µs making 147 calls to Foswiki::Infix::Node::newNode, avg 5µs/call |
67 | } | ||||
68 | |||||
69 | =begin TML | ||||
70 | |||||
71 | ---++ ObjectMethod convertToLeaf( $type, $val ) | ||||
72 | |||||
73 | Convert the node into a terminal node. | ||||
74 | * =$type= - one of NAME, NUMBER, STRING | ||||
75 | * =$val= - the (scalar) value of the leaf | ||||
76 | |||||
77 | Not used by the Foswiki::Infix::Parser. | ||||
78 | |||||
79 | =cut | ||||
80 | |||||
81 | # spent 282µs within Foswiki::Infix::Node::convertToLeaf which was called 80 times, avg 4µs/call:
# 80 times (282µs+0s) by Foswiki::Query::Node::_freeze at line 379 of /var/www/foswikidev/core/lib/Foswiki/Query/Node.pm, avg 4µs/call | ||||
82 | 80 | 70µs | my ( $this, $type, $val ) = @_; | ||
83 | 80 | 35µs | $this->{op} = $type; | ||
84 | 80 | 235µs | $this->{params} = [$val]; | ||
85 | } | ||||
86 | |||||
87 | =begin TML | ||||
88 | |||||
89 | ---++ ObjectMethod isLeaf() -> $boolean | ||||
90 | |||||
91 | Return true if this node was created by =newLeaf()= (or converted by =convertToLeaf=) | ||||
92 | |||||
93 | =cut | ||||
94 | |||||
95 | sub isLeaf { | ||||
96 | my $this = shift; | ||||
97 | return !ref( $this->{op} ); | ||||
98 | } | ||||
99 | |||||
100 | =begin TML | ||||
101 | |||||
102 | ---++ ObjectMethod stringify() -> $string | ||||
103 | |||||
104 | Generate a string representation of the subtree, for reporting. The representation | ||||
105 | generated by this function should be parseable, but is not guaranteed to be. | ||||
106 | |||||
107 | =cut | ||||
108 | |||||
109 | sub stringify { | ||||
110 | my $this = shift; | ||||
111 | |||||
112 | unless ( ref( $this->{op} ) ) { | ||||
113 | if ( $this->{op} == STRING ) { | ||||
114 | ASSERT( ref( $this->{params}[0] ) eq '' ) if DEBUG; | ||||
115 | return "'$this->{params}[0]'"; | ||||
116 | } | ||||
117 | else { | ||||
118 | if ( ref( $this->{params}[0] ) eq 'HASH' ) { | ||||
119 | return join( ',', | ||||
120 | map { $_ . "=>'" . $this->{params}[0]->{$_} . "'" } | ||||
121 | sort keys( %{ $this->{params}[0] } ) ); | ||||
122 | } | ||||
123 | if ( ref( $this->{params}[0] ) eq 'Foswiki::Meta' ) { | ||||
124 | return $this->{params}[0]->web . '.' | ||||
125 | . $this->{params}[0]->topic; | ||||
126 | } | ||||
127 | return $this->{params}[0]; | ||||
128 | } | ||||
129 | } | ||||
130 | if ( $this->{op}->{arity} ) { | ||||
131 | 2 | 168µs | 1 | 3.08ms | # spent 3.08ms (1.80+1.28) within Foswiki::Infix::Node::BEGIN@131 which was called:
# once (1.80ms+1.28ms) by Foswiki::Infix::Parser::BEGIN@26 at line 131 # spent 3.08ms making 1 call to Foswiki::Infix::Node::BEGIN@131 |
132 | return | ||||
133 | $this->{op}->{name} . '{' | ||||
134 | . join( ',', map { stringify($_) } @{ $this->{params} } ) . '}'; | ||||
135 | } | ||||
136 | else { | ||||
137 | $this->{op}->{name}; | ||||
138 | } | ||||
139 | } | ||||
140 | |||||
141 | 1 | 2µs | 1; | ||
142 | __END__ |