← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/local/src/github.com/foswiki/core/bin/view
  Run on Sun Dec 4 17:17:59 2011
Reported on Sun Dec 4 17:26:43 2011

Filename/usr/local/src/github.com/foswiki/core/lib/Foswiki/AggregateIterator.pm
StatementsExecuted 450 statements in 2.32ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
3832936µs1.97msFoswiki::AggregateIterator::::hasNextFoswiki::AggregateIterator::hasNext
111462µs713µsFoswiki::AggregateIterator::::BEGIN@16Foswiki::AggregateIterator::BEGIN@16
1811445µs5.71msFoswiki::AggregateIterator::::nextFoswiki::AggregateIterator::next
1811182µs182µsFoswiki::AggregateIterator::::uniqueFoswiki::AggregateIterator::unique
21162µs62µsFoswiki::AggregateIterator::::newFoswiki::AggregateIterator::new
11124µs31µsFoswiki::AggregateIterator::::BEGIN@13Foswiki::AggregateIterator::BEGIN@13
11116µs34µsFoswiki::AggregateIterator::::BEGIN@14Foswiki::AggregateIterator::BEGIN@14
Call graph for these subroutines as a Graphviz dot language file.
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
8Combine multiple iterators into a single iteration.
9
10=cut
11
12package Foswiki::AggregateIterator;
13245µs238µ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
use strict;
# spent 31µs making 1 call to Foswiki::AggregateIterator::BEGIN@13 # spent 7µs making 1 call to strict::import
14243µs251µ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
use warnings;
# spent 34µs making 1 call to Foswiki::AggregateIterator::BEGIN@14 # spent 18µs making 1 call to warnings::import
15
162645µs1713µ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
use Foswiki::Iterator ();
# spent 713µs making 1 call to Foswiki::AggregateIterator::BEGIN@16
17110µsour @ISA = ('Foswiki::Iterator');
18
19=begin TML
20
21---++ new(\@list, $unique)
22
23Create a new iterator over the given list of iterators. The list is
24not damaged in any way.
25
26If =$unique= is set, we try to not repeat values.
27Warning: =$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
sub new {
32665µs my ( $class, $list, $unique ) = @_;
33 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 return $this;
47}
48
49=begin TML
50
51---++ hasNext() -> $boolean
52
53Returns 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
sub hasNext {
58152391µs my ($this) = @_;
59 return 1 if $this->{next};
60 my $n;
61 do {
62623µs unless ( $this->{list} ) {
631231µs if ( $this->{Itr_index} < scalar( @{ $this->{Itr_list} } ) ) {
64 $this->{list} = $this->{Itr_list}->[ $this->{Itr_index}++ ];
65 }
66 else {
67 return 0; #no more iterators in list
68 }
69 }
7022111µs22463µs if ( $this->{list}->hasNext() ) {
# spent 463µs making 22 calls to Foswiki::ListIterator::hasNext, avg 21µs/call
7118386µs $n = $this->{list}->next();
# spent 386µs making 18 calls to Foswiki::ListIterator::next, avg 21µs/call
72 }
73 else {
74 $this->{list} = undef; #goto next iterator
75 }
76 } while ( !$this->{list}
7746342µs18182µ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 $this->{next} = $n;
80 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
sub unique {
843664µs my ( $this, $value ) = @_;
85
8636145µs unless ( defined( $this->{unique_hash}{$value} ) ) {
87 $this->{unique_hash}{$value} = 1;
88 return 1;
89 }
90
91 return 0;
92}
93
94=begin TML
95
96---++ next() -> $data
97
98Return the next entry in the list.
99
100The iterator object can be customised to pre- and post-process entries from
101the list before returning them. This is done by setting two fields in the
102iterator 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
sub next {
113108375µs my $this = shift;
1141892µs $this->hasNext();
# spent 92µs making 18 calls to Foswiki::AggregateIterator::hasNext, avg 5µs/call
115 my $n = $this->{next};
116 $this->{next} = undef;
1171827µs185.18ms $n = &{ $this->{process} }($n) if $this->{process};
118
119 #print STDERR "next - $n \n";
120 return $n;
121}
122
12316µs1;
124__END__