Filename | /var/www/foswiki11/lib/Foswiki/Query/Node.pm |
Statements | Executed 444941 statements in 1.16s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
26433 | 12 | 8 | 1.04s | 2.00s | evaluate (recurses: max depth 2, inclusive time 1.24s) | Foswiki::Query::Node::
114522 | 9 | 2 | 96.3ms | 96.3ms | MONITOR_EVAL | Foswiki::Query::Node::
242 | 3 | 2 | 2.79ms | 5.95ms | simplify (recurses: max depth 1, inclusive time 3.09ms) | Foswiki::Query::Node::
320 | 3 | 2 | 2.44ms | 2.74ms | toString (recurses: max depth 4, inclusive time 5.69ms) | Foswiki::Query::Node::
140 | 3 | 1 | 1.93ms | 3.51ms | newLeaf | Foswiki::Query::Node::
403 | 3 | 3 | 1.24ms | 1.87ms | evaluatesToConstant (recurses: max depth 1, inclusive time 304µs) | Foswiki::Query::Node::
1 | 1 | 1 | 33µs | 51µs | BEGIN@101 | Foswiki::Query::Node::
1 | 1 | 1 | 24µs | 48µs | BEGIN@29 | Foswiki::Query::Node::
1 | 1 | 1 | 19µs | 36µs | BEGIN@183 | Foswiki::Query::Node::
1 | 1 | 1 | 18µs | 37µs | BEGIN@185 | Foswiki::Query::Node::
1 | 1 | 1 | 17µs | 48µs | BEGIN@117 | Foswiki::Query::Node::
1 | 1 | 1 | 17µs | 33µs | BEGIN@217 | Foswiki::Query::Node::
1 | 1 | 1 | 16µs | 31µs | BEGIN@239 | Foswiki::Query::Node::
1 | 1 | 1 | 16µs | 40µs | BEGIN@34 | Foswiki::Query::Node::
1 | 1 | 1 | 16µs | 37µs | BEGIN@258 | Foswiki::Query::Node::
1 | 1 | 1 | 15µs | 25µs | BEGIN@30 | Foswiki::Query::Node::
1 | 1 | 1 | 15µs | 224µs | BEGIN@35 | Foswiki::Query::Node::
1 | 1 | 1 | 15µs | 34µs | BEGIN@219 | Foswiki::Query::Node::
1 | 1 | 1 | 8µs | 8µs | BEGIN@37 | Foswiki::Query::Node::
1 | 1 | 1 | 7µs | 7µs | BEGIN@31 | Foswiki::Query::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::Query::Node | ||||
6 | |||||
7 | A Query object is a representation of a query over the Foswiki database. | ||||
8 | |||||
9 | Fields are given by name, and values by strings or numbers. Strings should always be surrounded by 'single-quotes'. Numbers can be signed integers or decimals. Single quotes in values may be escaped using backslash (\). | ||||
10 | |||||
11 | See %SYSTEMWEB%.QuerySearch for details of the query language. At the time of writing | ||||
12 | only a subset of the entire query language is supported, for use in searching. | ||||
13 | |||||
14 | A query object implements the =evaluate= method as its general | ||||
15 | contract with the rest of the world. This method does a "hard work" evaluation | ||||
16 | of the parser tree. Of course, smarter Store implementations should be | ||||
17 | able to do it better.... | ||||
18 | |||||
19 | The "hard work" evaluation uses the =getField= method in the | ||||
20 | {Store}{QueryAlgorithm} to get data from the store. This decouples the query | ||||
21 | object from the detail of the store. | ||||
22 | |||||
23 | See Foswiki::Store::QueryAlgorithms for a full spec of the interface to | ||||
24 | query algorithms. | ||||
25 | |||||
26 | =cut | ||||
27 | |||||
28 | package Foswiki::Query::Node; | ||||
29 | 2 | 48µs | 2 | 71µs | # spent 48µs (24+24) within Foswiki::Query::Node::BEGIN@29 which was called:
# once (24µs+24µs) by Foswiki::Query::Parser::BEGIN@20 at line 29 # spent 48µs making 1 call to Foswiki::Query::Node::BEGIN@29
# spent 24µs making 1 call to strict::import |
30 | 2 | 42µs | 2 | 34µs | # spent 25µs (15+10) within Foswiki::Query::Node::BEGIN@30 which was called:
# once (15µs+10µs) by Foswiki::Query::Parser::BEGIN@20 at line 30 # spent 25µs making 1 call to Foswiki::Query::Node::BEGIN@30
# spent 10µs making 1 call to warnings::import |
31 | 2 | 62µs | 1 | 7µs | # spent 7µs within Foswiki::Query::Node::BEGIN@31 which was called:
# once (7µs+0s) by Foswiki::Query::Parser::BEGIN@20 at line 31 # spent 7µs making 1 call to Foswiki::Query::Node::BEGIN@31 |
32 | 1 | 15µs | our @ISA = ('Foswiki::Infix::Node'); | ||
33 | |||||
34 | 2 | 46µs | 2 | 63µs | # spent 40µs (16+24) within Foswiki::Query::Node::BEGIN@34 which was called:
# once (16µs+24µs) by Foswiki::Query::Parser::BEGIN@20 at line 34 # spent 40µs making 1 call to Foswiki::Query::Node::BEGIN@34
# spent 24µs making 1 call to Assert::import |
35 | 2 | 51µs | 2 | 433µs | # spent 224µs (15+209) within Foswiki::Query::Node::BEGIN@35 which was called:
# once (15µs+209µs) by Foswiki::Query::Parser::BEGIN@20 at line 35 # spent 224µs making 1 call to Foswiki::Query::Node::BEGIN@35
# spent 209µs making 1 call to Error::import |
36 | |||||
37 | 2 | 383µs | 1 | 8µs | # spent 8µs within Foswiki::Query::Node::BEGIN@37 which was called:
# once (8µs+0s) by Foswiki::Query::Parser::BEGIN@20 at line 37 # spent 8µs making 1 call to Foswiki::Query::Node::BEGIN@37 |
38 | |||||
39 | # Cache of the names of $Foswiki::cfg items that are accessible | ||||
40 | 1 | 200ns | our $isAccessibleCfg; | ||
41 | |||||
42 | =begin TML | ||||
43 | |||||
44 | ---++ PUBLIC %aliases | ||||
45 | A hash mapping short aliases for META: entry names. For example, this hash | ||||
46 | maps 'form' to 'META:FORM'. Published because extensions (search | ||||
47 | implementations) have made use of it in the past, though not part of the | ||||
48 | offical API. | ||||
49 | |||||
50 | This hash is maintained by Foswiki::Meta and is *strictly read-only* | ||||
51 | |||||
52 | ---++ PUBLIC %isArrayType | ||||
53 | Maps META: entry type names to true if the type is an array type (such as | ||||
54 | FIELD, ATTACHMENT or PREFERENCE). Published because extensions (search | ||||
55 | implementations) have made use of it in the past, though not part of the | ||||
56 | offical API. The type name should be given without the leading 'META:' | ||||
57 | |||||
58 | This hash is maintained by Foswiki::Meta and is *strictly read-only* | ||||
59 | |||||
60 | =cut | ||||
61 | |||||
62 | # These used to be declared here, but have been refactored back into | ||||
63 | # Foswiki::Meta | ||||
64 | 1 | 2µs | *aliases = \%Foswiki::Meta::aliases; | ||
65 | 1 | 400ns | *isArrayType = \%Foswiki::Meta::isArrayType; | ||
66 | |||||
67 | # <DEBUG SUPPORT> | ||||
68 | |||||
69 | 114522 | 428ms | # spent 96.3ms within Foswiki::Query::Node::MONITOR_EVAL which was called 114522 times, avg 841ns/call:
# 26433 times (23.7ms+0s) by Foswiki::Query::Node::evaluate at line 189, avg 897ns/call
# 26433 times (20.4ms+0s) by Foswiki::Query::Node::evaluate at line 148, avg 772ns/call
# 8852 times (7.41ms+0s) by Foswiki::Query::Node::evaluate at line 176, avg 837ns/call
# 8821 times (9.02ms+0s) by Foswiki::Query::Node::evaluate at line 186, avg 1µs/call
# 8821 times (7.02ms+0s) by Foswiki::Query::Node::evaluate at line 181, avg 796ns/call
# 8821 times (6.30ms+0s) by Foswiki::Query::Node::evaluate at line 187, avg 714ns/call
# 8821 times (5.78ms+0s) by Foswiki::Query::Node::evaluate at line 182, avg 656ns/call
# 8760 times (9.10ms+0s) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 240 of /var/www/foswiki11/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 1µs/call
# 8760 times (7.52ms+0s) by Foswiki::Query::Node::evaluate at line 155, avg 858ns/call | ||
70 | |||||
71 | # We expand config vars to constant strings during the parse, because otherwise we'd | ||||
72 | # have to export the knowledge of config vars out to other engines that may | ||||
73 | # evaluate queries instead of the default evaluator. | ||||
74 | # spent 3.51ms (1.93+1.58) within Foswiki::Query::Node::newLeaf which was called 140 times, avg 25µs/call:
# 81 times (1.41ms+1.09ms) by Foswiki::Infix::Parser::__ANON__[/var/www/foswiki11/lib/Foswiki/Infix/Parser.pm:277] at line 253 of /var/www/foswiki11/lib/Foswiki/Infix/Parser.pm, avg 31µs/call
# 58 times (499µs+464µs) by Foswiki::Infix::Parser::__ANON__[/var/www/foswiki11/lib/Foswiki/Infix/Parser.pm:277] at line 239 of /var/www/foswiki11/lib/Foswiki/Infix/Parser.pm, avg 17µs/call
# once (20µs+23µs) by Foswiki::Infix::Parser::__ANON__[/var/www/foswiki11/lib/Foswiki/Infix/Parser.pm:277] at line 246 of /var/www/foswiki11/lib/Foswiki/Infix/Parser.pm | ||||
75 | 140 | 202µs | my ( $class, $val, $type ) = @_; | ||
76 | |||||
77 | 140 | 253µs | if ( $type == $Foswiki::Infix::Node::NAME | ||
78 | && $val =~ /^({[A-Z][A-Z0-9_]*})+$/i ) | ||||
79 | { | ||||
80 | |||||
81 | # config var name, make sure it's accessible. | ||||
82 | 1 | 4µs | unless ( defined $isAccessibleCfg ) { | ||
83 | $isAccessibleCfg = | ||||
84 | 1 | 70µs | { map { $_ => 1 } @{ $Foswiki::cfg{AccessibleCFG} } }; | ||
85 | } | ||||
86 | $val = | ||||
87 | 1 | 34µs | ( $isAccessibleCfg->{$val} ) ? eval( '$Foswiki::cfg' . $val ) : ''; # spent 3µs executing statements in string eval | ||
88 | 1 | 15µs | 1 | 21µs | return $class->SUPER::newLeaf( $val, $Foswiki::Infix::Node::STRING ); # spent 21µs making 1 call to Foswiki::Infix::Node::newLeaf |
89 | } | ||||
90 | else { | ||||
91 | 139 | 1.42ms | 139 | 1.56ms | return $class->SUPER::newLeaf( $val, $type ); # spent 1.56ms making 139 calls to Foswiki::Infix::Node::newLeaf, avg 11µs/call |
92 | } | ||||
93 | } | ||||
94 | |||||
95 | # spent 2.74ms (2.44+299µs) within Foswiki::Query::Node::toString which was called 320 times, avg 9µs/call:
# 160 times (940µs+-940µs) by Foswiki::Query::Node::toString at line 110, avg 0s/call
# 120 times (1.03ms+-1.03ms) by Foswiki::Query::Node::toString at line 102, avg 0s/call
# 40 times (466µs+2.27ms) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 184 of /var/www/foswiki11/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 68µs/call | ||||
96 | 320 | 85µs | my $a = shift; | ||
97 | 320 | 44µs | return 'undef' unless defined($a); | ||
98 | |||||
99 | # Suppress the recursion check; the tree can easily be more than | ||||
100 | # 100 levels deep. | ||||
101 | 2 | 210µs | 2 | 70µs | # spent 51µs (33+18) within Foswiki::Query::Node::BEGIN@101 which was called:
# once (33µs+18µs) by Foswiki::Query::Parser::BEGIN@20 at line 101 # spent 51µs making 1 call to Foswiki::Query::Node::BEGIN@101
# spent 18µs making 1 call to warnings::unimport |
102 | 320 | 1.40ms | 440 | 244µs | if ( UNIVERSAL::isa( $a, 'Foswiki::Query::Node' ) ) { # spent 244µs making 320 calls to UNIVERSAL::isa, avg 764ns/call
# spent 3.39ms making 120 calls to Foswiki::Query::Node::toString, avg 28µs/call, recursion: max depth 3, sum of overlapping time 3.39ms |
103 | return | ||||
104 | '{ op => ' | ||||
105 | . $a->{op} | ||||
106 | . ', params => ' | ||||
107 | . toString( $a->{params} ) . ' }'; | ||||
108 | } | ||||
109 | 200 | 117µs | if ( ref($a) eq 'ARRAY' ) { | ||
110 | 280 | 674µs | 160 | 0s | return '[' . join( ',', map { toString($_) } @$a ) . ']'; # spent 2.30ms making 160 calls to Foswiki::Query::Node::toString, avg 14µs/call, recursion: max depth 4, sum of overlapping time 2.30ms |
111 | } | ||||
112 | 80 | 22µs | if ( ref($a) eq 'HASH' ) { | ||
113 | return | ||||
114 | '{' | ||||
115 | . join( ',', map { "$_=>" . toString( $a->{$_} ) } keys %$a ) . '}'; | ||||
116 | } | ||||
117 | 2 | 454µs | 2 | 79µs | # spent 48µs (17+31) within Foswiki::Query::Node::BEGIN@117 which was called:
# once (17µs+31µs) by Foswiki::Query::Parser::BEGIN@20 at line 117 # spent 48µs making 1 call to Foswiki::Query::Node::BEGIN@117
# spent 31µs making 1 call to warnings::import |
118 | 80 | 196µs | 80 | 55µs | if ( UNIVERSAL::isa( $a, 'Foswiki::Meta' ) ) { # spent 55µs making 80 calls to UNIVERSAL::isa, avg 686ns/call |
119 | return $a->stringify(); | ||||
120 | } | ||||
121 | 80 | 196µs | return $a; | ||
122 | } | ||||
123 | |||||
124 | 1 | 500ns | my $ind = 0; | ||
125 | |||||
126 | # </DEBUG SUPPORT> | ||||
127 | |||||
128 | # Evaluate this node by invoking the operator function named in the 'exec' | ||||
129 | # field of the operator. The return result is either an array ref (for many | ||||
130 | # results) or a scalar (for a single result) | ||||
131 | # | ||||
132 | # This is the default evaluator for queries. However it may not be the only | ||||
133 | # engine that evaluates them; external engines, such as SQL, might be delegated | ||||
134 | # the responsibility of evaluating queries in a search context. | ||||
135 | # | ||||
136 | # Note that the name resolution simply executes the getField function in the | ||||
137 | # query algorithm. It is placed there to allow for Store specific optimisations | ||||
138 | # such as direct database lookups. | ||||
139 | # | ||||
140 | # SMELL: is the getField passed enough domain information? It can see the data | ||||
141 | # object (usually a Meta) but cannot see the context of the name in the query. | ||||
142 | # | ||||
143 | # spent 2.00s (1.04+957ms) within Foswiki::Query::Node::evaluate which was called 26433 times, avg 76µs/call:
# 8767 times (186ms+-186ms) by Foswiki::Query::BinaryOP::evalTest at line 42 of /var/www/foswiki11/lib/Foswiki/Query/BinaryOP.pm, avg 0s/call
# 8767 times (539ms+-539ms) by Foswiki::Query::BinaryOP::evalTest at line 41 of /var/www/foswiki11/lib/Foswiki/Query/BinaryOP.pm, avg 0s/call
# 8760 times (316ms+1.67s) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 242 of /var/www/foswiki11/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 227µs/call
# 82 times (1.12ms+246µs) by Foswiki::Query::Node::simplify at line 241, avg 17µs/call
# 41 times (1.05ms+10.5ms) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/IF.pm:43] at line 35 of /var/www/foswiki11/lib/Foswiki/Macros/IF.pm, avg 280µs/call
# 6 times (132µs+-132µs) by Foswiki::Query::OP_and::evaluate at line 27 of /var/www/foswiki11/lib/Foswiki/Query/OP_and.pm, avg 0s/call
# 4 times (109µs+-109µs) by Foswiki::Query::OP_and::evaluate at line 29 of /var/www/foswiki11/lib/Foswiki/Query/OP_and.pm, avg 0s/call
# 2 times (57µs+-57µs) by Foswiki::Query::OP_or::evaluate at line 27 of /var/www/foswiki11/lib/Foswiki/Query/OP_or.pm, avg 0s/call
# once (33µs+8µs) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/QUERY.pm:56] at line 53 of /var/www/foswiki11/lib/Foswiki/Macros/QUERY.pm
# once (19µs+4µs) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 117 of /var/www/foswiki11/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm
# once (27µs+-27µs) by Foswiki::Query::OP_or::evaluate at line 29 of /var/www/foswiki11/lib/Foswiki/Query/OP_or.pm
# once (24µs+-24µs) by Foswiki::Query::OP_not::evaluate at line 26 of /var/www/foswiki11/lib/Foswiki/Query/OP_not.pm | ||||
144 | 26433 | 6.47ms | my $this = shift; | ||
145 | 26433 | 38.6ms | 26433 | 23.5ms | ASSERT( scalar(@_) % 2 == 0 ); # spent 23.5ms making 26433 calls to Assert::dummyASSERT, avg 889ns/call |
146 | 26433 | 3.84ms | my $result; | ||
147 | |||||
148 | 26433 | 29.7ms | 26433 | 20.4ms | print STDERR ( '-' x $ind ) . $this->stringify() if MONITOR_EVAL; # spent 20.4ms making 26433 calls to Foswiki::Query::Node::MONITOR_EVAL, avg 772ns/call |
149 | |||||
150 | 26433 | 25.9ms | if ( !ref( $this->{op} ) ) { | ||
151 | 17612 | 23.7ms | my %domain = @_; | ||
152 | 17612 | 30.1ms | if ( $this->{op} == $Foswiki::Infix::Node::NAME | ||
153 | && defined $domain{data} ) | ||||
154 | { | ||||
155 | 8760 | 8.79ms | 8760 | 7.52ms | print STDERR '.' if MONITOR_EVAL; # spent 7.52ms making 8760 calls to Foswiki::Query::Node::MONITOR_EVAL, avg 858ns/call |
156 | 8760 | 12.9ms | if ( lc( $this->{params}[0] ) eq 'now' ) { | ||
157 | $result = time(); | ||||
158 | } | ||||
159 | elsif ( lc( $this->{params}[0] ) eq 'undefined' ) { | ||||
160 | $result = undef; | ||||
161 | } | ||||
162 | else { | ||||
163 | |||||
164 | # a name; look it up in $domain{data} | ||||
165 | 8760 | 227ms | eval "require $Foswiki::cfg{Store}{QueryAlgorithm}"; # spent 21.9ms executing statements in 8760 string evals (merged) | ||
166 | 8760 | 1.46ms | if ($@) { | ||
167 | print STDERR ' BOOM ' if MONITOR_EVAL; | ||||
168 | die $@; | ||||
169 | } | ||||
170 | $result = | ||||
171 | 8760 | 45.5ms | 8760 | 448ms | $Foswiki::cfg{Store}{QueryAlgorithm} # spent 448ms making 8760 calls to Foswiki::Store::QueryAlgorithms::BruteForce::getField, avg 51µs/call |
172 | ->getField( $this, $domain{data}, $this->{params}[0] ); | ||||
173 | } | ||||
174 | } | ||||
175 | else { | ||||
176 | 8852 | 8.86ms | 8852 | 7.41ms | print STDERR ',' if MONITOR_EVAL; # spent 7.41ms making 8852 calls to Foswiki::Query::Node::MONITOR_EVAL, avg 837ns/call |
177 | 8852 | 6.88ms | $result = $this->{params}[0]; | ||
178 | } | ||||
179 | } | ||||
180 | else { | ||||
181 | 8821 | 8.84ms | 8821 | 7.02ms | print STDERR " {\n" if MONITOR_EVAL; # spent 7.02ms making 8821 calls to Foswiki::Query::Node::MONITOR_EVAL, avg 796ns/call |
182 | 8821 | 7.52ms | 8821 | 5.78ms | $ind++ if MONITOR_EVAL; # spent 5.78ms making 8821 calls to Foswiki::Query::Node::MONITOR_EVAL, avg 656ns/call |
183 | 2 | 74µs | 2 | 52µs | # spent 36µs (19+17) within Foswiki::Query::Node::BEGIN@183 which was called:
# once (19µs+17µs) by Foswiki::Query::Parser::BEGIN@20 at line 183 # spent 36µs making 1 call to Foswiki::Query::Node::BEGIN@183
# spent 17µs making 1 call to warnings::unimport |
184 | 8821 | 39.7ms | 8821 | 1.64s | $result = $this->{op}->evaluate( $this, @_ ); # spent 1.62s making 8762 calls to Foswiki::Query::OP_eq::evaluate, avg 185µs/call
# spent 6.96ms making 18 calls to Foswiki::If::OP_dollar::evaluate, avg 387µs/call
# spent 2.58ms making 6 calls to Foswiki::Query::OP_and::evaluate, avg 429µs/call
# spent 2.40ms making 5 calls to Foswiki::Query::OP_ne::evaluate, avg 479µs/call
# spent 923µs making 12 calls to Foswiki::If::OP_defined::evaluate, avg 77µs/call
# spent 856µs making 7 calls to Foswiki::If::OP_istopic::evaluate, avg 122µs/call
# spent 1.41ms making 2 calls to Foswiki::Query::OP_or::evaluate, avg 703µs/call, recursion: max depth 1, sum of overlapping time 683µs
# spent 259µs making 8 calls to Foswiki::If::OP_context::evaluate, avg 32µs/call
# spent 70µs making 1 call to Foswiki::Query::OP_not::evaluate |
185 | 2 | 253µs | 2 | 56µs | # spent 37µs (18+19) within Foswiki::Query::Node::BEGIN@185 which was called:
# once (18µs+19µs) by Foswiki::Query::Parser::BEGIN@20 at line 185 # spent 37µs making 1 call to Foswiki::Query::Node::BEGIN@185
# spent 19µs making 1 call to warnings::import |
186 | 8821 | 12.1ms | 8821 | 9.02ms | $ind-- if MONITOR_EVAL; # spent 9.02ms making 8821 calls to Foswiki::Query::Node::MONITOR_EVAL, avg 1µs/call |
187 | 8821 | 10.8ms | 8821 | 6.30ms | print STDERR ( '-' x $ind ) . '}' . $this->{op}->{name} if MONITOR_EVAL; # spent 6.30ms making 8821 calls to Foswiki::Query::Node::MONITOR_EVAL, avg 714ns/call |
188 | } | ||||
189 | 26433 | 28.0ms | 26433 | 23.7ms | print STDERR ' -> ' . toString($result) . "\n" if MONITOR_EVAL; # spent 23.7ms making 26433 calls to Foswiki::Query::Node::MONITOR_EVAL, avg 897ns/call |
190 | |||||
191 | 26433 | 142ms | return $result; | ||
192 | } | ||||
193 | |||||
194 | =begin TML | ||||
195 | |||||
196 | ---++ evaluatesToConstant(%opts) | ||||
197 | |||||
198 | Determine if this node evaluates to a constant or not. "Constant" is defined | ||||
199 | as "anything that doesn't involve actually looking in searched topics". | ||||
200 | This function takes the same parameters (%domain) as evaluate(). Note that | ||||
201 | no reference to the tom or data web or topic will be made, so you can | ||||
202 | simply pass an arbitrary Foswiki::Meta. | ||||
203 | |||||
204 | =cut | ||||
205 | |||||
206 | # spent 1.87ms (1.24+634µs) within Foswiki::Query::Node::evaluatesToConstant which was called 403 times, avg 5µs/call:
# 242 times (780µs+740µs) by Foswiki::Query::Node::simplify at line 240, avg 6µs/call
# 120 times (304µs+-304µs) by Foswiki::Query::BinaryOP::evaluatesToConstant at line 69 of /var/www/foswiki11/lib/Foswiki/Query/BinaryOP.pm, avg 0s/call
# 41 times (155µs+199µs) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 110 of /var/www/foswiki11/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 9µs/call | ||||
207 | 403 | 73µs | my $this = shift; | ||
208 | 403 | 572µs | if ( | ||
209 | !ref( $this->{op} ) | ||||
210 | && ( $this->{op} == $Foswiki::Infix::Node::NUMBER | ||||
211 | || $this->{op} == $Foswiki::Infix::Node::STRING ) | ||||
212 | ) | ||||
213 | { | ||||
214 | return 1; | ||||
215 | } | ||||
216 | elsif ( ref( $this->{op} ) ) { | ||||
217 | 2 | 67µs | 2 | 49µs | # spent 33µs (17+16) within Foswiki::Query::Node::BEGIN@217 which was called:
# once (17µs+16µs) by Foswiki::Query::Parser::BEGIN@20 at line 217 # spent 33µs making 1 call to Foswiki::Query::Node::BEGIN@217
# spent 16µs making 1 call to warnings::unimport |
218 | 120 | 476µs | 120 | 938µs | return $this->{op}->evaluatesToConstant( $this, @_ ); # spent 938µs making 120 calls to Foswiki::Query::BinaryOP::evaluatesToConstant, avg 8µs/call |
219 | 2 | 117µs | 2 | 53µs | # spent 34µs (15+19) within Foswiki::Query::Node::BEGIN@219 which was called:
# once (15µs+19µs) by Foswiki::Query::Parser::BEGIN@20 at line 219 # spent 34µs making 1 call to Foswiki::Query::Node::BEGIN@219
# spent 19µs making 1 call to warnings::import |
220 | } | ||||
221 | 200 | 479µs | return 0; | ||
222 | } | ||||
223 | |||||
224 | =begin TML | ||||
225 | |||||
226 | ---++ simplify(%opts) | ||||
227 | |||||
228 | Simplify the query by spotting constant expressions and evaluating them, | ||||
229 | replacing the constant expression with an atomic value in the expression tree. | ||||
230 | This function takes the same parameters (%domain) as evaluate(). Note that | ||||
231 | no reference to the tom or data web or topic will be made, so you can | ||||
232 | simply pass an arbitrary Foswiki::Meta. | ||||
233 | |||||
234 | =cut | ||||
235 | |||||
236 | # spent 5.95ms (2.79+3.16) within Foswiki::Query::Node::simplify which was called 242 times, avg 25µs/call:
# 160 times (1.47ms+-1.47ms) by Foswiki::Query::Node::simplify at line 253, avg 0s/call
# 41 times (814µs+2.76ms) by Foswiki::Store::QueryAlgorithms::BruteForce::query at line 48 of /var/www/foswiki11/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 87µs/call
# 41 times (502µs+1.87ms) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 109 of /var/www/foswiki11/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 58µs/call | ||||
237 | 242 | 64µs | my $this = shift; | ||
238 | |||||
239 | 2 | 240µs | 2 | 46µs | # spent 31µs (16+15) within Foswiki::Query::Node::BEGIN@239 which was called:
# once (16µs+15µs) by Foswiki::Query::Parser::BEGIN@20 at line 239 # spent 31µs making 1 call to Foswiki::Query::Node::BEGIN@239
# spent 15µs making 1 call to warnings::unimport |
240 | 242 | 810µs | 242 | 1.52ms | if ( $this->evaluatesToConstant(@_) ) { # spent 1.52ms making 242 calls to Foswiki::Query::Node::evaluatesToConstant, avg 6µs/call |
241 | 82 | 156µs | 82 | 1.37ms | my $c = $this->evaluate(@_); # spent 1.37ms making 82 calls to Foswiki::Query::Node::evaluate, avg 17µs/call |
242 | 82 | 34µs | $c = 0 unless defined $c; | ||
243 | 82 | 279µs | if ( $c =~ /^[+-]?(\d+\.\d+|\d+\.|\.\d+|\d+)([eE][+-]?\d+)?$/ ) { | ||
244 | $this->{op} = $Foswiki::Infix::Node::NUMBER; | ||||
245 | } | ||||
246 | else { | ||||
247 | 80 | 62µs | $this->{op} = $Foswiki::Infix::Node::STRING; | ||
248 | } | ||||
249 | 82 | 158µs | @{ $this->{params} } = ($c); | ||
250 | } | ||||
251 | else { | ||||
252 | 160 | 205µs | for my $f ( @{ $this->{params} } ) { | ||
253 | 240 | 1.05ms | 400 | 273µs | if ( UNIVERSAL::can( $f, 'simplify' ) ) { # spent 273µs making 240 calls to UNIVERSAL::can, avg 1µs/call
# spent 3.09ms making 160 calls to Foswiki::Query::Node::simplify, avg 19µs/call, recursion: max depth 1, sum of overlapping time 3.09ms |
254 | $f->simplify(@_); | ||||
255 | } | ||||
256 | } | ||||
257 | } | ||||
258 | 2 | 75µs | 2 | 58µs | # spent 37µs (16+21) within Foswiki::Query::Node::BEGIN@258 which was called:
# once (16µs+21µs) by Foswiki::Query::Parser::BEGIN@20 at line 258 # spent 37µs making 1 call to Foswiki::Query::Node::BEGIN@258
# spent 21µs making 1 call to warnings::import |
259 | } | ||||
260 | |||||
261 | 1 | 7µs | 1; | ||
262 | __END__ |