Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/AggregateIterator.pm |
Statements | Executed 450 statements in 2.32ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
38 | 3 | 2 | 936µs | 1.97ms | hasNext | Foswiki::AggregateIterator::
1 | 1 | 1 | 462µs | 713µs | BEGIN@16 | Foswiki::AggregateIterator::
18 | 1 | 1 | 445µs | 5.71ms | next | Foswiki::AggregateIterator::
18 | 1 | 1 | 182µs | 182µs | unique | Foswiki::AggregateIterator::
2 | 1 | 1 | 62µs | 62µs | new | Foswiki::AggregateIterator::
1 | 1 | 1 | 24µs | 31µs | BEGIN@13 | Foswiki::AggregateIterator::
1 | 1 | 1 | 16µs | 34µs | BEGIN@14 | Foswiki::AggregateIterator::
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::AggregateIterator | ||||
6 | *implements* Foswiki::Iterator | ||||
7 | |||||
8 | Combine multiple iterators into a single iteration. | ||||
9 | |||||
10 | =cut | ||||
11 | |||||
12 | package Foswiki::AggregateIterator; | ||||
13 | 2 | 45µs | 2 | 38µs | # spent 31µs (24+7) within Foswiki::AggregateIterator::BEGIN@13 which was called:
# once (24µs+7µs) by Foswiki::Users::BEGIN@63 at line 13 # spent 31µs making 1 call to Foswiki::AggregateIterator::BEGIN@13
# spent 7µs making 1 call to strict::import |
14 | 2 | 43µs | 2 | 51µs | # spent 34µs (16+18) within Foswiki::AggregateIterator::BEGIN@14 which was called:
# once (16µs+18µs) by Foswiki::Users::BEGIN@63 at line 14 # spent 34µs making 1 call to Foswiki::AggregateIterator::BEGIN@14
# spent 18µs making 1 call to warnings::import |
15 | |||||
16 | 2 | 645µs | 1 | 713µs | # spent 713µs (462+252) within Foswiki::AggregateIterator::BEGIN@16 which was called:
# once (462µs+252µs) by Foswiki::Users::BEGIN@63 at line 16 # spent 713µs making 1 call to Foswiki::AggregateIterator::BEGIN@16 |
17 | 1 | 10µs | our @ISA = ('Foswiki::Iterator'); | ||
18 | |||||
19 | =begin TML | ||||
20 | |||||
21 | ---++ new(\@list, $unique) | ||||
22 | |||||
23 | Create a new iterator over the given list of iterators. The list is | ||||
24 | not damaged in any way. | ||||
25 | |||||
26 | If =$unique= is set, we try to not repeat values. | ||||
27 | Warning: =$unique= assumes that the values are strings. | ||||
28 | |||||
29 | =cut | ||||
30 | |||||
31 | # spent 62µs within Foswiki::AggregateIterator::new which was called 2 times, avg 31µs/call:
# 2 times (62µs+0s) by Foswiki::Users::eachGroupMember at line 806 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Users.pm, avg 31µs/call | ||||
32 | 2 | 7µs | my ( $class, $list, $unique ) = @_; | ||
33 | 2 | 39µs | my $this = bless( | ||
34 | { | ||||
35 | Itr_list => $list, | ||||
36 | Itr_index => 0, | ||||
37 | index => 0, | ||||
38 | process => undef, | ||||
39 | filter => undef, | ||||
40 | next => undef, | ||||
41 | unique => $unique, | ||||
42 | unique_hash => {} | ||||
43 | }, | ||||
44 | $class | ||||
45 | ); | ||||
46 | 2 | 19µs | return $this; | ||
47 | } | ||||
48 | |||||
49 | =begin TML | ||||
50 | |||||
51 | ---++ hasNext() -> $boolean | ||||
52 | |||||
53 | Returns false when the iterator is exhausted. | ||||
54 | |||||
55 | =cut | ||||
56 | |||||
57 | # spent 1.97ms (936µs+1.03) within Foswiki::AggregateIterator::hasNext which was called 38 times, avg 52µs/call:
# 18 times (664µs+885µs) by Foswiki::Contrib::MailerContrib::WebNotify::subscribe at line 136 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Contrib/MailerContrib/WebNotify.pm, avg 86µs/call
# 18 times (92µs+0s) by Foswiki::AggregateIterator::next at line 114, avg 5µs/call
# 2 times (180µs+146µs) by Foswiki::Contrib::MailerContrib::WebNotify::subscribe at line 134 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Contrib/MailerContrib/WebNotify.pm, avg 163µs/call | ||||
58 | 38 | 64µs | my ($this) = @_; | ||
59 | 38 | 129µs | return 1 if $this->{next}; | ||
60 | 20 | 21µs | my $n; | ||
61 | do { | ||||
62 | 24 | 39µs | unless ( $this->{list} ) { | ||
63 | 12 | 32µs | if ( $this->{Itr_index} < scalar( @{ $this->{Itr_list} } ) ) { | ||
64 | 4 | 12µs | $this->{list} = $this->{Itr_list}->[ $this->{Itr_index}++ ]; | ||
65 | } | ||||
66 | else { | ||||
67 | 2 | 10µs | return 0; #no more iterators in list | ||
68 | } | ||||
69 | } | ||||
70 | 22 | 144µs | 22 | 463µs | if ( $this->{list}->hasNext() ) { # spent 463µs making 22 calls to Foswiki::ListIterator::hasNext, avg 21µs/call |
71 | 18 | 103µs | 18 | 386µs | $n = $this->{list}->next(); # spent 386µs making 18 calls to Foswiki::ListIterator::next, avg 21µs/call |
72 | } | ||||
73 | else { | ||||
74 | 4 | 8µs | $this->{list} = undef; #goto next iterator | ||
75 | } | ||||
76 | } while ( !$this->{list} | ||||
77 | 20 | 207µs | 18 | 182µs | || ( $this->{filter} && !&{ $this->{filter} }($n) ) # spent 182µs making 18 calls to Foswiki::AggregateIterator::unique, avg 10µs/call |
78 | || ( $this->{unique} && !$this->unique($n) ) ); | ||||
79 | 18 | 30µs | $this->{next} = $n; | ||
80 | 18 | 99µs | return 1; | ||
81 | } | ||||
82 | |||||
83 | # spent 182µs within Foswiki::AggregateIterator::unique which was called 18 times, avg 10µs/call:
# 18 times (182µs+0s) by Foswiki::AggregateIterator::hasNext at line 77, avg 10µs/call | ||||
84 | 18 | 32µs | my ( $this, $value ) = @_; | ||
85 | |||||
86 | 18 | 31µs | unless ( defined( $this->{unique_hash}{$value} ) ) { | ||
87 | 18 | 38µs | $this->{unique_hash}{$value} = 1; | ||
88 | 18 | 108µs | return 1; | ||
89 | } | ||||
90 | |||||
91 | return 0; | ||||
92 | } | ||||
93 | |||||
94 | =begin TML | ||||
95 | |||||
96 | ---++ next() -> $data | ||||
97 | |||||
98 | Return the next entry in the list. | ||||
99 | |||||
100 | The iterator object can be customised to pre- and post-process entries from | ||||
101 | the list before returning them. This is done by setting two fields in the | ||||
102 | iterator object: | ||||
103 | |||||
104 | * ={filter}= can be defined to be a sub that filters each entry. The entry | ||||
105 | will be ignored (next() will not return it) if the filter returns false. | ||||
106 | * ={process}= can be defined to be a sub to process each entry before it | ||||
107 | is returned by next. The value returned from next is the value returned | ||||
108 | by the process function. | ||||
109 | |||||
110 | =cut | ||||
111 | |||||
112 | # spent 5.71ms (445µs+5.27) within Foswiki::AggregateIterator::next which was called 18 times, avg 317µs/call:
# 18 times (445µs+5.27ms) by Foswiki::Contrib::MailerContrib::WebNotify::subscribe at line 135 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Contrib/MailerContrib/WebNotify.pm, avg 317µs/call | ||||
113 | 18 | 27µs | my $this = shift; | ||
114 | 18 | 76µs | 18 | 92µs | $this->hasNext(); # spent 92µs making 18 calls to Foswiki::AggregateIterator::hasNext, avg 5µs/call |
115 | 18 | 29µs | my $n = $this->{next}; | ||
116 | 18 | 30µs | $this->{next} = undef; | ||
117 | 36 | 152µs | 18 | 5.18ms | $n = &{ $this->{process} }($n) if $this->{process}; # spent 5.18ms making 18 calls to Foswiki::Func::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Func.pm:1252], avg 288µs/call |
118 | |||||
119 | #print STDERR "next - $n \n"; | ||||
120 | 18 | 89µs | return $n; | ||
121 | } | ||||
122 | |||||
123 | 1 | 6µs | 1; | ||
124 | __END__ |