Filename | /var/www/foswikidev/core/lib/Foswiki/Query/OP.pm |
Statements | Executed 9516 statements in 55.1ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
8849 | 2 | 2 | 36.7ms | 36.7ms | isNumber | Foswiki::Query::OP::
120 | 1 | 1 | 701µs | 981µs | evaluatesToConstant | Foswiki::Query::OP::
91 | 15 | 15 | 546µs | 546µs | new | Foswiki::Query::OP::
1 | 1 | 1 | 13µs | 24µs | BEGIN@16 | Foswiki::Query::OP::
1 | 1 | 1 | 9µs | 13µs | BEGIN@17 | Foswiki::Query::OP::
0 | 0 | 0 | 0s | 0s | collect | Foswiki::Query::OP::
0 | 0 | 0 | 0s | 0s | evaluate | Foswiki::Query::OP::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | package Foswiki::Query::OP; | ||||
3 | |||||
4 | =begin TML | ||||
5 | |||||
6 | ---+ package Foswiki::Query::OP | ||||
7 | Base class of operators used in queries. Operators are singleton | ||||
8 | objects that specify the parser behaviour and are attached to | ||||
9 | nodes in the parse tree to provide semantics for the nodes. | ||||
10 | |||||
11 | See Foswiki::Infix::OP for details of the different options used | ||||
12 | to define operator nodes. | ||||
13 | |||||
14 | =cut | ||||
15 | |||||
16 | 2 | 24µs | 2 | 36µs | # spent 24µs (13+12) within Foswiki::Query::OP::BEGIN@16 which was called:
# once (13µs+12µs) by Foswiki::Query::OP_empty::BEGIN@14 at line 16 # spent 24µs making 1 call to Foswiki::Query::OP::BEGIN@16
# spent 12µs making 1 call to strict::import |
17 | 2 | 267µs | 2 | 16µs | # spent 13µs (9+4) within Foswiki::Query::OP::BEGIN@17 which was called:
# once (9µs+4µs) by Foswiki::Query::OP_empty::BEGIN@14 at line 17 # spent 13µs making 1 call to Foswiki::Query::OP::BEGIN@17
# spent 4µs making 1 call to warnings::import |
18 | |||||
19 | # Does not need to subclass, but is a subclass of... | ||||
20 | #use Foswiki::Infix::OP (); | ||||
21 | #our @ISA = ( 'Foswiki::Infix::OP' ); | ||||
22 | |||||
23 | # spent 546µs within Foswiki::Query::OP::new which was called 91 times, avg 6µs/call:
# 30 times (183µs+0s) by Foswiki::Query::UnaryOP::new at line 18 of /var/www/foswikidev/core/lib/Foswiki/Query/UnaryOP.pm, avg 6µs/call
# 27 times (180µs+0s) by Foswiki::Query::ConditionalOP::new at line 18 of /var/www/foswikidev/core/lib/Foswiki/Query/ConditionalOP.pm, avg 7µs/call
# 4 times (22µs+0s) by Foswiki::Query::OP_comma::new at line 22 of /var/www/foswikidev/core/lib/Foswiki/Query/OP_comma.pm, avg 6µs/call
# 3 times (19µs+0s) by Foswiki::Query::OP_plus::new at line 19 of /var/www/foswikidev/core/lib/Foswiki/Query/OP_plus.pm, avg 6µs/call
# 3 times (17µs+0s) by Foswiki::Query::OP_minus::new at line 19 of /var/www/foswikidev/core/lib/Foswiki/Query/OP_minus.pm, avg 6µs/call
# 3 times (17µs+0s) by Foswiki::Query::OP_dot::new at line 19 of /var/www/foswikidev/core/lib/Foswiki/Query/OP_dot.pm, avg 6µs/call
# 3 times (15µs+0s) by Foswiki::Query::OP_and::new at line 23 of /var/www/foswikidev/core/lib/Foswiki/Query/OP_and.pm, avg 5µs/call
# 3 times (14µs+0s) by Foswiki::Query::OP_ref::new at line 21 of /var/www/foswikidev/core/lib/Foswiki/Query/OP_ref.pm, avg 5µs/call
# 3 times (14µs+0s) by Foswiki::Query::OP_or::new at line 23 of /var/www/foswikidev/core/lib/Foswiki/Query/OP_or.pm, avg 5µs/call
# 3 times (14µs+0s) by Foswiki::Query::OP_where::new at line 19 of /var/www/foswikidev/core/lib/Foswiki/Query/OP_where.pm, avg 5µs/call
# 3 times (13µs+0s) by Foswiki::Query::OP_times::new at line 19 of /var/www/foswikidev/core/lib/Foswiki/Query/OP_times.pm, avg 4µs/call
# 3 times (13µs+0s) by Foswiki::Query::OP_div::new at line 19 of /var/www/foswikidev/core/lib/Foswiki/Query/OP_div.pm, avg 4µs/call
# once (10µs+0s) by Foswiki::Query::OP_empty::new at line 19 of /var/www/foswikidev/core/lib/Foswiki/Query/OP_empty.pm
# once (6µs+0s) by Foswiki::If::OP_allows::new at line 30 of /var/www/foswikidev/core/lib/Foswiki/If/OP_allows.pm
# once (6µs+0s) by Foswiki::If::OP_ingroup::new at line 27 of /var/www/foswikidev/core/lib/Foswiki/If/OP_ingroup.pm | ||||
24 | 91 | 169µs | my ( $class, %opts ) = @_; | ||
25 | 91 | 520µs | return bless( \%opts, $class ); | ||
26 | } | ||||
27 | |||||
28 | =begin TML | ||||
29 | |||||
30 | ---++ ObjectMethod evaluate($node, %domain) -> $value | ||||
31 | |||||
32 | Pure virtual method that evaluates the operator in the give domain. | ||||
33 | The domain is a reference to a hash that contains the | ||||
34 | data being operated on, and a reference to the meta-data of the topic being worked on | ||||
35 | (the "topic object"). The data being operated on can be a | ||||
36 | Meta object, a reference to an array (such as attachments), a reference | ||||
37 | to a hash or a scalar. Arrays can contain other arrays | ||||
38 | and hashes. | ||||
39 | |||||
40 | See Foswiki::Query::Node::evaluate for more information. | ||||
41 | |||||
42 | =cut | ||||
43 | |||||
44 | sub evaluate { | ||||
45 | my $this = shift; | ||||
46 | die "Operator '$this->{name}' does not define evaluate()"; | ||||
47 | } | ||||
48 | |||||
49 | =begin TML | ||||
50 | |||||
51 | ---++ ObjectMethod evaluatesToConstant() -> $boolean | ||||
52 | Does this operator always evaluate to a constant? | ||||
53 | See Foswiki::Query::Node::evaluatesToConstant | ||||
54 | |||||
55 | Used in hoisting/optimisation. | ||||
56 | |||||
57 | Default behaviour is to call evaluatesAsConstant on all | ||||
58 | parameters and return true if they all return true. | ||||
59 | |||||
60 | =cut | ||||
61 | |||||
62 | # spent 981µs (701+280) within Foswiki::Query::OP::evaluatesToConstant which was called 120 times, avg 8µs/call:
# 120 times (701µs+280µs) by Foswiki::Query::Node::evaluatesToConstant at line 316 of /var/www/foswikidev/core/lib/Foswiki/Query/Node.pm, avg 8µs/call | ||||
63 | 120 | 30µs | my $this = shift; | ||
64 | 120 | 23µs | my $node = shift; | ||
65 | 120 | 119µs | foreach my $i ( @{ $node->{params} } ) { | ||
66 | 120 | 438µs | 120 | 0s | return 0 unless $i->evaluatesToConstant(@_); # spent 280µs making 120 calls to Foswiki::Query::Node::evaluatesToConstant, avg 2µs/call, recursion: max depth 1, sum of overlapping time 280µs |
67 | } | ||||
68 | return 1; | ||||
69 | } | ||||
70 | |||||
71 | =begin TML | ||||
72 | |||||
73 | ---++ StaticMethod isNumber($string) -> $boolean | ||||
74 | |||||
75 | Determine if a string represents a valid number (signed decimal) | ||||
76 | |||||
77 | Used in hoisting/optimisation. | ||||
78 | |||||
79 | =cut | ||||
80 | |||||
81 | # spent 36.7ms within Foswiki::Query::OP::isNumber which was called 8849 times, avg 4µs/call:
# 8769 times (36.4ms+0s) by Foswiki::Query::ConditionalOP::compare at line 41 of /var/www/foswikidev/core/lib/Foswiki/Query/ConditionalOP.pm, avg 4µs/call
# 80 times (301µs+0s) by Foswiki::Query::Node::_freeze at line 364 of /var/www/foswikidev/core/lib/Foswiki/Query/Node.pm, avg 4µs/call | ||||
82 | 8849 | 53.5ms | return shift =~ m/^[+-]?(\d+\.\d+|\d+\.|\.\d+|\d+)([eE][+-]?\d+)?$/; | ||
83 | } | ||||
84 | |||||
85 | =begin TML | ||||
86 | |||||
87 | ---++ StaticMethod collect($a, $fn) -> [] | ||||
88 | |||||
89 | Invokes $fn once for each element of $a and return an array built from the results. | ||||
90 | |||||
91 | =cut | ||||
92 | |||||
93 | sub collect { | ||||
94 | my ( $this, $a, $fn ) = @_; | ||||
95 | if ( ref($a) eq 'ARRAY' ) { | ||||
96 | my @b = map { $this->collect( $_, $fn ) } @$a; | ||||
97 | return \@b; | ||||
98 | } | ||||
99 | elsif ( ref($a) eq 'HASH' ) { | ||||
100 | die "Can't collect on a hash"; | ||||
101 | } | ||||
102 | else { | ||||
103 | return &$fn($a); | ||||
104 | } | ||||
105 | } | ||||
106 | |||||
107 | 1 | 2µs | 1; | ||
108 | __END__ |