Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Iterator/FilterIterator.pm |
Statements | Executed 10898 statements in 70.6ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
94 | 7 | 4 | 80.7ms | 1.94s | hasNext | Foswiki::Iterator::FilterIterator::
45 | 3 | 3 | 647µs | 880µs | next | Foswiki::Iterator::FilterIterator::
3 | 3 | 2 | 136µs | 156µs | new | Foswiki::Iterator::FilterIterator::
1 | 1 | 1 | 50µs | 57µs | BEGIN@13 | Foswiki::Iterator::FilterIterator::
1 | 1 | 1 | 27µs | 40µs | reset | Foswiki::Iterator::FilterIterator::
1 | 1 | 1 | 17µs | 35µs | BEGIN@14 | Foswiki::Iterator::FilterIterator::
1 | 1 | 1 | 16µs | 55µs | BEGIN@15 | Foswiki::Iterator::FilterIterator::
1 | 1 | 1 | 9µs | 9µs | BEGIN@17 | Foswiki::Iterator::FilterIterator::
0 | 0 | 0 | 0s | 0s | nextWeb | Foswiki::Iterator::FilterIterator::
0 | 0 | 0 | 0s | 0s | numberOfTopics | Foswiki::Iterator::FilterIterator::
0 | 0 | 0 | 0s | 0s | skip | Foswiki::Iterator::FilterIterator::
0 | 0 | 0 | 0s | 0s | sortResults | Foswiki::Iterator::FilterIterator::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | =begin | ||||
4 | |||||
5 | ---+ package Foswiki::Iterator::FilterIterator | ||||
6 | |||||
7 | Iterator that filters another iterator based on the results from a function. | ||||
8 | |||||
9 | =cut | ||||
10 | |||||
11 | package Foswiki::Iterator::FilterIterator; | ||||
12 | |||||
13 | 2 | 55µs | 2 | 64µs | # spent 57µs (50+7) within Foswiki::Iterator::FilterIterator::BEGIN@13 which was called:
# once (50µs+7µs) by Foswiki::Search::InfoCache::BEGIN@26 at line 13 # spent 57µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@13
# spent 7µs making 1 call to strict::import |
14 | 2 | 44µs | 2 | 52µs | # spent 35µs (17+18) within Foswiki::Iterator::FilterIterator::BEGIN@14 which was called:
# once (17µs+18µs) by Foswiki::Search::InfoCache::BEGIN@26 at line 14 # spent 35µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@14
# spent 18µs making 1 call to warnings::import |
15 | 2 | 44µs | 2 | 93µs | # spent 55µs (16+38) within Foswiki::Iterator::FilterIterator::BEGIN@15 which was called:
# once (16µs+38µs) by Foswiki::Search::InfoCache::BEGIN@26 at line 15 # spent 55µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@15
# spent 38µs making 1 call to Assert::import |
16 | |||||
17 | 2 | 923µs | 1 | 9µs | # spent 9µs within Foswiki::Iterator::FilterIterator::BEGIN@17 which was called:
# once (9µs+0s) by Foswiki::Search::InfoCache::BEGIN@26 at line 17 # spent 9µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@17 |
18 | 1 | 15µs | our @ISA = ('Foswiki::Iterator'); | ||
19 | |||||
20 | =begin TML | ||||
21 | |||||
22 | ---++ ClassMethod new( $iter, $sub, $data ) | ||||
23 | Construct a new iterator that will filter $iter based on the results from | ||||
24 | $sub. $sub should return 0 if the next() from $iter should be filtered and | ||||
25 | 1 if it should be treated as the next item in the sequence. | ||||
26 | |||||
27 | $data is an optional arbitrary data item which will be passed to $sub in $_[1] | ||||
28 | |||||
29 | =cut | ||||
30 | |||||
31 | # spent 156µs (136+21) within Foswiki::Iterator::FilterIterator::new which was called 3 times, avg 52µs/call:
# once (55µs+7µs) by Foswiki::Store::Interfaces::QueryAlgorithm::getWebIterator at line 230 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm
# once (45µs+7µs) by Foswiki::Search::InfoCache::getTopicListIterator at line 459 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Search/InfoCache.pm
# once (36µs+7µs) by Foswiki::Store::Interfaces::QueryAlgorithm::addACLFilter at line 188 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm | ||||
32 | 3 | 9µs | my ( $class, $iter, $sub, $data ) = @_; | ||
33 | 3 | 14µs | 3 | 11µs | ASSERT( UNIVERSAL::isa( $iter, 'Foswiki::Iterator' ) ) if DEBUG; # spent 11µs making 3 calls to Assert::ASSERTS_OFF, avg 4µs/call |
34 | 3 | 14µs | 3 | 10µs | ASSERT( ref($sub) eq 'CODE' ) if DEBUG; # spent 10µs making 3 calls to Assert::ASSERTS_OFF, avg 3µs/call |
35 | 3 | 27µs | my $this = bless( {}, $class ); | ||
36 | 3 | 9µs | $this->{iterator} = $iter; | ||
37 | 3 | 6µs | $this->{filter} = $sub; | ||
38 | 3 | 6µs | $this->{data} = $data; | ||
39 | 3 | 5µs | $this->{next} = undef; | ||
40 | 3 | 6µs | $this->{pending} = 0; | ||
41 | 3 | 25µs | return $this; | ||
42 | } | ||||
43 | |||||
44 | #lie - give the unfiltered count for speed. | ||||
45 | sub numberOfTopics { | ||||
46 | my $this = shift; | ||||
47 | return $this->{iterator}->numberOfTopics(); | ||||
48 | } | ||||
49 | |||||
50 | sub nextWeb { | ||||
51 | my $this = shift; | ||||
52 | $this->{iterator}->nextWeb(); | ||||
53 | } | ||||
54 | |||||
55 | sub sortResults { | ||||
56 | my $this = shift; | ||||
57 | $this->{iterator}->sortResults(@_); | ||||
58 | } | ||||
59 | |||||
60 | # See Foswiki::Iterator for a description of the general iterator contract | ||||
61 | # spent 1.94s (80.7ms+1.86) within Foswiki::Iterator::FilterIterator::hasNext which was called 94 times, avg 20.7ms/call:
# 45 times (234µs+0s) by Foswiki::Iterator::FilterIterator::next at line 118, avg 5µs/call
# 22 times (779µs+1.64s) by Foswiki::Search::formatResults at line 1018 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Search.pm, avg 74.7ms/call
# 22 times (79.4ms+213ms) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 181 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 13.3ms/call
# 2 times (65µs+641µs) by Foswiki::Iterator::ProcessIterator::hasNext at line 45 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Iterator/ProcessIterator.pm, avg 353µs/call
# once (43µs+3.59ms) by Foswiki::Search::searchWeb at line 371 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Search.pm
# once (92µs+225µs) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 175 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm
# once (7µs+0s) by Foswiki::Search::formatResults at line 711 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Search.pm | ||||
62 | 94 | 133µs | my $this = shift; | ||
63 | 94 | 334µs | return 1 if $this->{pending}; | ||
64 | 48 | 279µs | 48 | 2.60ms | while ( $this->{iterator}->hasNext() ) { # spent 2.02ms making 23 calls to Foswiki::Search::ResultSet::hasNext, avg 88µs/call
# spent 581µs making 25 calls to Foswiki::ListIterator::hasNext, avg 23µs/call |
65 | 3448 | 19.8ms | 3448 | 72.7ms | $this->{next} = $this->{iterator}->next(); # spent 72.2ms making 3426 calls to Foswiki::ListIterator::next, avg 21µs/call
# spent 471µs making 22 calls to Foswiki::Search::ResultSet::next, avg 21µs/call |
66 | 6896 | 47.9ms | 6851 | 1.79s | if ( &{ $this->{filter} }( $this->{next}, $this->{data} ) ) { # spent 1.64s making 22 calls to Foswiki::Store::Interfaces::QueryAlgorithm::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm:187], avg 74.7ms/call
# spent 76.8ms making 3403 calls to Foswiki::ListIterator::hasNext, avg 23µs/call
# spent 63.8ms making 3425 calls to Foswiki::Search::InfoCache::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Search/InfoCache.pm:424], avg 19µs/call
# spent 567µs making 1 call to Foswiki::Store::Interfaces::QueryAlgorithm::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm:228] |
67 | 45 | 77µs | $this->{pending} = 1; | ||
68 | 45 | 286µs | return 1; | ||
69 | } | ||||
70 | } | ||||
71 | 3 | 14µs | return 0; | ||
72 | } | ||||
73 | |||||
74 | #WARNING: foswiki has always skipped results before evaluating the filter - this is for speed, but a terrible thing to do | ||||
75 | sub skip { | ||||
76 | my $this = shift; | ||||
77 | my $count = shift; | ||||
78 | |||||
79 | #ask CAN skip() for faster path | ||||
80 | if ( $this->{iterator}->can('skip') ) { | ||||
81 | $count = $this->{iterator}->skip($count); | ||||
82 | |||||
83 | #SMELL, TODO, AAAARGH - don't want to drain the itr, but this is assuming too much. | ||||
84 | $this->{next} = $this->{iterator}->{next}; | ||||
85 | } | ||||
86 | else { | ||||
87 | |||||
88 | #brute force | ||||
89 | while ( | ||||
90 | ( $count > 0 | ||||
91 | ) #must come first - don't want to advance the inner itr if count ==0 | ||||
92 | and $this->{iterator}->hasNext() | ||||
93 | ) | ||||
94 | { | ||||
95 | $count--; | ||||
96 | $this->{next} = | ||||
97 | $this->{iterator}->next() | ||||
98 | ; #drain next, so hasNext goes to next element | ||||
99 | } | ||||
100 | } | ||||
101 | |||||
102 | if ( $count >= 0 ) { | ||||
103 | |||||
104 | #finished. | ||||
105 | $this->{next} = undef; | ||||
106 | $this->{pending} = 0; | ||||
107 | } | ||||
108 | print STDERR | ||||
109 | "--------------------------------------------FilterIterator::skip() => $count\n" | ||||
110 | if Foswiki::Iterator::MONITOR; | ||||
111 | |||||
112 | return $count; | ||||
113 | } | ||||
114 | |||||
115 | # See Foswiki::Iterator for a description of the general iterator contract | ||||
116 | # spent 880µs (647+234) within Foswiki::Iterator::FilterIterator::next which was called 45 times, avg 20µs/call:
# 22 times (326µs+117µs) by Foswiki::Search::formatResults at line 712 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Search.pm, avg 20µs/call
# 22 times (304µs+112µs) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 176 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 19µs/call
# once (17µs+5µs) by Foswiki::Iterator::ProcessIterator::next at line 51 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Iterator/ProcessIterator.pm | ||||
117 | 45 | 68µs | my $this = shift; | ||
118 | 45 | 218µs | 45 | 234µs | return unless $this->hasNext(); # spent 234µs making 45 calls to Foswiki::Iterator::FilterIterator::hasNext, avg 5µs/call |
119 | 45 | 67µs | $this->{pending} = 0; | ||
120 | 45 | 253µs | return $this->{next}; | ||
121 | } | ||||
122 | |||||
123 | # See Foswiki::Iterator for a description of the general iterator contract | ||||
124 | # spent 40µs (27+12) within Foswiki::Iterator::FilterIterator::reset which was called:
# once (27µs+12µs) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 174 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm | ||||
125 | 1 | 2µs | my ($this) = @_; | ||
126 | |||||
127 | 1 | 10µs | 1 | 12µs | return unless ( $this->{iterator}->reset() ); # spent 12µs making 1 call to Foswiki::ListIterator::reset |
128 | 1 | 2µs | $this->{next} = undef; | ||
129 | 1 | 1µs | $this->{pending} = 0; | ||
130 | |||||
131 | 1 | 12µs | return 1; | ||
132 | } | ||||
133 | |||||
134 | 1 | 6µs | 1; | ||
135 | __END__ |