Filename | /var/www/foswikidev/core/lib/Foswiki/Iterator/FilterIterator.pm |
Statements | Executed 931131 statements in 1.62s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
173480 | 9 | 5 | 1.60s | 57.0s | hasNext | Foswiki::Iterator::FilterIterator::
63640 | 4 | 4 | 452ms | 523ms | next | Foswiki::Iterator::FilterIterator::
120 | 3 | 2 | 5.12ms | 5.57ms | reset | Foswiki::Iterator::FilterIterator::
200 | 3 | 2 | 1.76ms | 1.76ms | new | Foswiki::Iterator::FilterIterator::
80 | 1 | 1 | 629µs | 182ms | sortResults | Foswiki::Iterator::FilterIterator::
1 | 1 | 1 | 14µs | 18µs | BEGIN@14 | Foswiki::Iterator::FilterIterator::
1 | 1 | 1 | 13µs | 25µs | BEGIN@13 | Foswiki::Iterator::FilterIterator::
1 | 1 | 1 | 9µs | 35µs | BEGIN@15 | Foswiki::Iterator::FilterIterator::
1 | 1 | 1 | 4µs | 4µs | BEGIN@17 | Foswiki::Iterator::FilterIterator::
1 | 1 | 1 | 4µs | 4µs | BEGIN@20 | 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::
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 | 30µs | 2 | 38µs | # spent 25µs (13+12) within Foswiki::Iterator::FilterIterator::BEGIN@13 which was called:
# once (13µs+12µs) by Foswiki::Search::InfoCache::BEGIN@33 at line 13 # spent 25µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@13
# spent 12µs making 1 call to strict::import |
14 | 2 | 24µs | 2 | 23µs | # spent 18µs (14+4) within Foswiki::Iterator::FilterIterator::BEGIN@14 which was called:
# once (14µs+4µs) by Foswiki::Search::InfoCache::BEGIN@33 at line 14 # spent 18µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@14
# spent 4µs making 1 call to warnings::import |
15 | 2 | 25µs | 2 | 61µs | # spent 35µs (9+26) within Foswiki::Iterator::FilterIterator::BEGIN@15 which was called:
# once (9µs+26µs) by Foswiki::Search::InfoCache::BEGIN@33 at line 15 # spent 35µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@15
# spent 26µs making 1 call to Exporter::import |
16 | |||||
17 | 2 | 56µs | 1 | 4µs | # spent 4µs within Foswiki::Iterator::FilterIterator::BEGIN@17 which was called:
# once (4µs+0s) by Foswiki::Search::InfoCache::BEGIN@33 at line 17 # spent 4µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@17 |
18 | 1 | 9µs | our @ISA = ('Foswiki::Iterator'); | ||
19 | |||||
20 | # spent 4µs within Foswiki::Iterator::FilterIterator::BEGIN@20 which was called:
# once (4µs+0s) by Foswiki::Search::InfoCache::BEGIN@33 at line 25 | ||||
21 | 1 | 5µs | if ( $Foswiki::cfg{UseLocale} ) { | ||
22 | require locale; | ||||
23 | import locale(); | ||||
24 | } | ||||
25 | 1 | 476µs | 1 | 4µs | } # spent 4µs making 1 call to Foswiki::Iterator::FilterIterator::BEGIN@20 |
26 | |||||
27 | =begin TML | ||||
28 | |||||
29 | ---++ ClassMethod new( $iter, $sub, $data ) | ||||
30 | Construct a new iterator that will filter $iter based on the results from | ||||
31 | $sub. $sub should return 0 if the next() from $iter should be filtered and | ||||
32 | 1 if it should be treated as the next item in the sequence. | ||||
33 | |||||
34 | $data is an optional arbitrary data item which will be passed to $sub in $_[1] | ||||
35 | |||||
36 | =cut | ||||
37 | |||||
38 | # spent 1.76ms within Foswiki::Iterator::FilterIterator::new which was called 200 times, avg 9µs/call:
# 80 times (1.05ms+0s) by Foswiki::Store::Interfaces::QueryAlgorithm::addACLFilter at line 195 of /var/www/foswikidev/core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm, avg 13µs/call
# 80 times (477µs+0s) by Foswiki::Store::Interfaces::QueryAlgorithm::getWebIterator at line 237 of /var/www/foswikidev/core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm, avg 6µs/call
# 40 times (226µs+0s) by Foswiki::Search::InfoCache::getTopicListIterator at line 482 of /var/www/foswikidev/core/lib/Foswiki/Search/InfoCache.pm, avg 6µs/call | ||||
39 | 200 | 240µs | my ( $class, $iter, $sub, $data ) = @_; | ||
40 | ASSERT( UNIVERSAL::isa( $iter, 'Foswiki::Iterator' ) ) if DEBUG; | ||||
41 | 200 | 24µs | ASSERT( ref($sub) eq 'CODE' ) if DEBUG; | ||
42 | 200 | 331µs | my $this = bless( {}, $class ); | ||
43 | 200 | 209µs | $this->{iterator} = $iter; | ||
44 | 200 | 105µs | $this->{filter} = $sub; | ||
45 | 200 | 163µs | $this->{data} = $data; | ||
46 | 200 | 119µs | $this->{next} = undef; | ||
47 | 200 | 128µs | $this->{pending} = 0; | ||
48 | 200 | 705µs | return $this; | ||
49 | } | ||||
50 | |||||
51 | #lie - give the unfiltered count for speed. | ||||
52 | sub numberOfTopics { | ||||
53 | my $this = shift; | ||||
54 | return $this->{iterator}->numberOfTopics(); | ||||
55 | } | ||||
56 | |||||
57 | sub nextWeb { | ||||
58 | my $this = shift; | ||||
59 | $this->{iterator}->nextWeb(); | ||||
60 | } | ||||
61 | |||||
62 | # spent 182ms (629µs+182) within Foswiki::Iterator::FilterIterator::sortResults which was called 80 times, avg 2.28ms/call:
# 80 times (629µs+182ms) by Foswiki::Store::Interfaces::QueryAlgorithm::query at line 140 of /var/www/foswikidev/core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm, avg 2.28ms/call | ||||
63 | 80 | 36µs | my $this = shift; | ||
64 | 80 | 735µs | 80 | 182ms | $this->{iterator}->sortResults(@_); # spent 182ms making 80 calls to Foswiki::Search::ResultSet::sortResults, avg 2.27ms/call |
65 | } | ||||
66 | |||||
67 | # See Foswiki::Iterator for a description of the general iterator contract | ||||
68 | # spent 57.0s (1.60+55.4) within Foswiki::Iterator::FilterIterator::hasNext which was called 173480 times, avg 329µs/call:
# 92000 times (1.11s+980ms) by Foswiki::Store::SearchAlgorithms::Forking::_search at line 139 of /var/www/foswikidev/core/lib/Foswiki/Store/SearchAlgorithms/Forking.pm, avg 23µs/call
# 63640 times (70.3ms+0s) by Foswiki::Iterator::FilterIterator::next at line 128, avg 1µs/call
# 8760 times (196ms+27.2s) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 188 of /var/www/foswikidev/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 3.13ms/call
# 8760 times (223ms+26.8s) by Foswiki::Search::formatResults at line 1071 of /var/www/foswikidev/core/lib/Foswiki/Search.pm, avg 3.09ms/call
# 160 times (1.48ms+16.1ms) by Foswiki::Iterator::ProcessIterator::hasNext at line 52 of /var/www/foswikidev/core/lib/Foswiki/Iterator/ProcessIterator.pm, avg 110µs/call
# 40 times (961µs+258ms) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 182 of /var/www/foswikidev/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 6.48ms/call
# 40 times (412µs+127ms) by Foswiki::Search::searchWeb at line 386 of /var/www/foswikidev/core/lib/Foswiki/Search.pm, avg 3.20ms/call
# 40 times (1.81ms+3.06ms) by Foswiki::Store::SearchAlgorithms::Forking::_search at line 134 of /var/www/foswikidev/core/lib/Foswiki/Store/SearchAlgorithms/Forking.pm, avg 122µs/call
# 40 times (64µs+0s) by Foswiki::Search::formatResults at line 750 of /var/www/foswikidev/core/lib/Foswiki/Search.pm, avg 2µs/call | ||||
69 | 173480 | 42.0ms | my $this = shift; | ||
70 | 173480 | 521ms | return 1 if $this->{pending}; | ||
71 | 63880 | 87.7ms | 63880 | 629ms | while ( $this->{iterator}->hasNext() ) { # spent 414ms making 17600 calls to Foswiki::Search::ResultSet::hasNext, avg 24µs/call
# spent 214ms making 46280 calls to Foswiki::ListIterator::hasNext, avg 5µs/call |
72 | 67880 | 127ms | 67880 | 511ms | $this->{next} = $this->{iterator}->next(); # spent 413ms making 50360 calls to Foswiki::ListIterator::next, avg 8µs/call
# spent 98.1ms making 17520 calls to Foswiki::Search::ResultSet::next, avg 6µs/call |
73 | 67880 | 139ms | 72120 | 54.3s | if ( &{ $this->{filter} }( $this->{next}, $this->{data} ) ) { # spent 53.9s making 17520 calls to Foswiki::Store::Interfaces::QueryAlgorithm::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm:194], avg 3.08ms/call
# spent 334ms making 50280 calls to Foswiki::Search::InfoCache::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Search/InfoCache.pm:448], avg 7µs/call
# spent 23.7ms making 4240 calls to Foswiki::ListIterator::hasNext, avg 6µs/call
# spent 15.0ms making 80 calls to Foswiki::Store::Interfaces::QueryAlgorithm::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm:235], avg 187µs/call |
74 | 63640 | 28.5ms | $this->{pending} = 1; | ||
75 | 63640 | 261ms | return 1; | ||
76 | } | ||||
77 | } | ||||
78 | 240 | 820µs | return 0; | ||
79 | } | ||||
80 | |||||
81 | #WARNING: foswiki has always skipped results before evaluating the filter - this is for speed, but a terrible thing to do | ||||
82 | sub skip { | ||||
83 | my $this = shift; | ||||
84 | my $count = shift; | ||||
85 | |||||
86 | #ask CAN skip() for faster path | ||||
87 | if ( $this->{iterator}->can('skip') ) { | ||||
88 | $count = $this->{iterator}->skip($count); | ||||
89 | |||||
90 | if ( $this->{iterator}->hasNext() ) { | ||||
91 | $this->{next} = $this->{iterator}->next(); | ||||
92 | $this->{pending} = 1; | ||||
93 | $count--; | ||||
94 | } | ||||
95 | } | ||||
96 | else { | ||||
97 | |||||
98 | #brute force | ||||
99 | while ( | ||||
100 | ( $count > 0 | ||||
101 | ) #must come first - don't want to advance the inner itr if count ==0 | ||||
102 | and $this->{iterator}->hasNext() | ||||
103 | ) | ||||
104 | { | ||||
105 | $count--; | ||||
106 | $this->{next} = | ||||
107 | $this->{iterator}->next() | ||||
108 | ; #drain next, so hasNext goes to next element | ||||
109 | } | ||||
110 | } | ||||
111 | |||||
112 | if ( $count >= 0 ) { | ||||
113 | |||||
114 | #skipped past the end of the set | ||||
115 | $this->{next} = undef; | ||||
116 | $this->{pending} = 0; | ||||
117 | } | ||||
118 | print STDERR | ||||
119 | "--------------------------------------------FilterIterator::skip() => $count\n" | ||||
120 | if Foswiki::Iterator::MONITOR; | ||||
121 | |||||
122 | return $count; | ||||
123 | } | ||||
124 | |||||
125 | # See Foswiki::Iterator for a description of the general iterator contract | ||||
126 | # spent 523ms (452+70.3) within Foswiki::Iterator::FilterIterator::next which was called 63640 times, avg 8µs/call:
# 46040 times (338ms+53.0ms) by Foswiki::Store::SearchAlgorithms::Forking::_search at line 135 of /var/www/foswikidev/core/lib/Foswiki/Store/SearchAlgorithms/Forking.pm, avg 8µs/call
# 8760 times (62.8ms+8.68ms) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 183 of /var/www/foswikidev/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 8µs/call
# 8760 times (51.3ms+8.52ms) by Foswiki::Search::formatResults at line 751 of /var/www/foswikidev/core/lib/Foswiki/Search.pm, avg 7µs/call
# 80 times (306µs+79µs) by Foswiki::Iterator::ProcessIterator::next at line 58 of /var/www/foswikidev/core/lib/Foswiki/Iterator/ProcessIterator.pm, avg 5µs/call | ||||
127 | 63640 | 16.6ms | my $this = shift; | ||
128 | 63640 | 59.5ms | 63640 | 70.3ms | return unless $this->hasNext(); # spent 70.3ms making 63640 calls to Foswiki::Iterator::FilterIterator::hasNext, avg 1µs/call |
129 | 63640 | 20.1ms | $this->{pending} = 0; | ||
130 | 63640 | 315ms | return $this->{next}; | ||
131 | } | ||||
132 | |||||
133 | # See Foswiki::Iterator for a description of the general iterator contract | ||||
134 | # spent 5.57ms (5.12+450µs) within Foswiki::Iterator::FilterIterator::reset which was called 120 times, avg 46µs/call:
# 40 times (4.18ms+66µs) by Foswiki::Store::SearchAlgorithms::Forking::_search at line 133 of /var/www/foswikidev/core/lib/Foswiki/Store/SearchAlgorithms/Forking.pm, avg 106µs/call
# 40 times (650µs+244µs) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 181 of /var/www/foswikidev/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 22µs/call
# 40 times (288µs+140µs) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 165 of /var/www/foswikidev/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 11µs/call | ||||
135 | 120 | 101µs | my ($this) = @_; | ||
136 | |||||
137 | 120 | 704µs | 120 | 450µs | return unless ( $this->{iterator}->reset() ); # spent 244µs making 40 calls to Foswiki::Iterator::reset, avg 6µs/call
# spent 206µs making 80 calls to Foswiki::ListIterator::reset, avg 3µs/call |
138 | 80 | 32µs | $this->{next} = undef; | ||
139 | 80 | 25µs | $this->{pending} = 0; | ||
140 | |||||
141 | 80 | 185µs | return 1; | ||
142 | } | ||||
143 | |||||
144 | 1 | 3µs | 1; | ||
145 | __END__ |