Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Infix/Node.pm |
Statements | Executed 1782 statements in 6.77ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
219 | 2 | 2 | 4.10ms | 4.10ms | newNode | Foswiki::Infix::Node::
1 | 1 | 1 | 3.26ms | 5.77ms | BEGIN@124 | Foswiki::Infix::Node::
115 | 2 | 1 | 1.41ms | 3.70ms | newLeaf | Foswiki::Infix::Node::
1 | 1 | 1 | 27µs | 35µs | BEGIN@14 | Foswiki::Infix::Node::
1 | 1 | 1 | 25µs | 318µs | BEGIN@22 | Foswiki::Infix::Node::
2 | 1 | 1 | 22µs | 22µs | convertToLeaf | Foswiki::Infix::Node::
1 | 1 | 1 | 20µs | 138µs | BEGIN@19 | Foswiki::Infix::Node::
1 | 1 | 1 | 16µs | 59µs | BEGIN@16 | Foswiki::Infix::Node::
1 | 1 | 1 | 16µs | 33µs | BEGIN@15 | 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 | 44µs | 2 | 42µs | # spent 35µs (27+7) within Foswiki::Infix::Node::BEGIN@14 which was called:
# once (27µs+7µs) by Foswiki::Infix::Parser::BEGIN@26 at line 14 # spent 35µs making 1 call to Foswiki::Infix::Node::BEGIN@14
# spent 7µs making 1 call to strict::import |
15 | 2 | 41µs | 2 | 50µs | # spent 33µs (16+17) within Foswiki::Infix::Node::BEGIN@15 which was called:
# once (16µs+17µs) by Foswiki::Infix::Parser::BEGIN@26 at line 15 # spent 33µs making 1 call to Foswiki::Infix::Node::BEGIN@15
# spent 17µs making 1 call to warnings::import |
16 | 2 | 49µs | 2 | 102µs | # spent 59µs (16+43) within Foswiki::Infix::Node::BEGIN@16 which was called:
# once (16µs+43µs) by Foswiki::Infix::Parser::BEGIN@26 at line 16 # spent 59µs making 1 call to Foswiki::Infix::Node::BEGIN@16
# spent 43µs making 1 call to Assert::import |
17 | |||||
18 | # 1 for debug | ||||
19 | 2 | 67µs | 2 | 256µs | # spent 138µs (20+118) within Foswiki::Infix::Node::BEGIN@19 which was called:
# once (20µs+118µs) by Foswiki::Infix::Parser::BEGIN@26 at line 19 # spent 138µs making 1 call to Foswiki::Infix::Node::BEGIN@19
# spent 118µs making 1 call to constant::import |
20 | |||||
21 | # Leaf token types | ||||
22 | # spent 318µs (25+292) within Foswiki::Infix::Node::BEGIN@22 which was called:
# once (25µs+292µs) by Foswiki::Infix::Parser::BEGIN@26 at line 28 | ||||
23 | 1 | 292µs | NAME => 1, # spent 292µs making 1 call to constant::import | ||
24 | NUMBER => 2, | ||||
25 | STRING => 3, | ||||
26 | HASH => 4, | ||||
27 | META => 5, | ||||
28 | 2 | 565µs | 1 | 318µs | }; # spent 318µs making 1 call to Foswiki::Infix::Node::BEGIN@22 |
29 | |||||
30 | =begin TML | ||||
31 | |||||
32 | ---++ ClassMethod newNode( $o, @p ) -> \$if | ||||
33 | |||||
34 | Construct a new parse node (contract with Infix::Parser) | ||||
35 | |||||
36 | =cut | ||||
37 | |||||
38 | # spent 4.10ms within Foswiki::Infix::Node::newNode which was called 219 times, avg 19µs/call:
# 115 times (2.30ms+0s) by Foswiki::Infix::Node::newLeaf at line 59, avg 20µs/call
# 104 times (1.81ms+0s) by Foswiki::Infix::Parser::_apply at line 350 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Infix/Parser.pm, avg 17µs/call | ||||
39 | 1314 | 3.88ms | my $class = shift; | ||
40 | my $op = shift; | ||||
41 | my $this = bless( {}, $class ); | ||||
42 | 219 | 654µs | @{ $this->{params} } = @_; | ||
43 | $this->{op} = $op; | ||||
44 | return $this; | ||||
45 | } | ||||
46 | |||||
47 | =begin TML | ||||
48 | |||||
49 | ---++ ClassMethod newLeaf( $val, $type ) -> \$if | ||||
50 | |||||
51 | Construct a new terminal node (contract with Infix::Parser) | ||||
52 | * =$val= - the (scalar) value of the leaf | ||||
53 | * =$type= - one of NAME, NUMBER, STRING | ||||
54 | |||||
55 | =cut | ||||
56 | |||||
57 | # spent 3.70ms (1.41+2.30) within Foswiki::Infix::Node::newLeaf which was called 115 times, avg 32µs/call:
# 114 times (1.39ms+2.27ms) by Foswiki::Query::Node::newLeaf at line 141 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/Node.pm, avg 32µs/call
# once (17µs+25µs) by Foswiki::Query::Node::newLeaf at line 138 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/Node.pm | ||||
58 | 230 | 1.17ms | my ( $class, $val, $type ) = @_; | ||
59 | 115 | 2.30ms | return newNode( $class, $type, $val ); # spent 2.30ms making 115 calls to Foswiki::Infix::Node::newNode, avg 20µs/call | ||
60 | } | ||||
61 | |||||
62 | =begin TML | ||||
63 | |||||
64 | ---++ ObjectMethod convertToLeaf( $type, $val ) | ||||
65 | |||||
66 | Convert the node into a terminal node. | ||||
67 | * =$type= - one of NAME, NUMBER, STRING | ||||
68 | * =$val= - the (scalar) value of the leaf | ||||
69 | |||||
70 | Not used by the Foswiki::Infix::Parser. | ||||
71 | |||||
72 | =cut | ||||
73 | |||||
74 | # spent 22µs within Foswiki::Infix::Node::convertToLeaf which was called 2 times, avg 11µs/call:
# 2 times (22µs+0s) by Foswiki::Query::Node::_freeze at line 374 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/Node.pm, avg 11µs/call | ||||
75 | 6 | 25µs | my ( $this, $type, $val ) = @_; | ||
76 | $this->{op} = $type; | ||||
77 | $this->{params} = [$val]; | ||||
78 | } | ||||
79 | |||||
80 | =begin TML | ||||
81 | |||||
82 | ---++ ObjectMethod isLeaf() -> $boolean | ||||
83 | |||||
84 | Return true if this node was created by =newLeaf()= (or converted by =convertToLeaf=) | ||||
85 | |||||
86 | =cut | ||||
87 | |||||
88 | sub isLeaf { | ||||
89 | my $this = shift; | ||||
90 | return !ref( $this->{op} ); | ||||
91 | } | ||||
92 | |||||
93 | =begin TML | ||||
94 | |||||
95 | ---++ ObjectMethod stringify() -> $string | ||||
96 | |||||
97 | Generate a string representation of the subtree, for reporting. The representation | ||||
98 | generated by this function should be parseable, but is not guaranteed to be. | ||||
99 | |||||
100 | =cut | ||||
101 | |||||
102 | sub stringify { | ||||
103 | my $this = shift; | ||||
104 | |||||
105 | unless ( ref( $this->{op} ) ) { | ||||
106 | if ( $this->{op} == STRING ) { | ||||
107 | ASSERT( ref( $this->{params}[0] ) eq '' ) if DEBUG; | ||||
108 | return "'$this->{params}[0]'"; | ||||
109 | } | ||||
110 | else { | ||||
111 | if ( ref( $this->{params}[0] ) eq 'HASH' ) { | ||||
112 | return join( ',', | ||||
113 | map { $_ . '=>' . $this->{params}[0]->{$_} } | ||||
114 | keys( %{ $this->{params}[0] } ) ); | ||||
115 | } | ||||
116 | if ( ref( $this->{params}[0] ) eq 'Foswiki::Meta' ) { | ||||
117 | return $this->{params}[0]->web . '.' | ||||
118 | . $this->{params}[0]->topic; | ||||
119 | } | ||||
120 | return $this->{params}[0]; | ||||
121 | } | ||||
122 | } | ||||
123 | if ( $this->{op}->{arity} ) { | ||||
124 | 2 | 279µs | 1 | 5.77ms | # spent 5.77ms (3.26+2.51) within Foswiki::Infix::Node::BEGIN@124 which was called:
# once (3.26ms+2.51ms) by Foswiki::Infix::Parser::BEGIN@26 at line 124 # spent 5.77ms making 1 call to Foswiki::Infix::Node::BEGIN@124 |
125 | return | ||||
126 | $this->{op}->{name} . '{' | ||||
127 | . join( ',', map { stringify($_) } @{ $this->{params} } ) . '}'; | ||||
128 | } | ||||
129 | else { | ||||
130 | $this->{op}->{name}; | ||||
131 | } | ||||
132 | } | ||||
133 | |||||
134 | 1 | 4µs | 1; | ||
135 | __END__ |