← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 19:05:14 2015
Reported on Fri Jul 31 19:08:09 2015

Filename/var/www/foswiki11/lib/Foswiki/AggregateIterator.pm
StatementsExecuted 8 statements in 428µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111270µs375µsFoswiki::AggregateIterator::::BEGIN@16Foswiki::AggregateIterator::BEGIN@16
11115µs28µsFoswiki::AggregateIterator::::BEGIN@13Foswiki::AggregateIterator::BEGIN@13
1118µs13µsFoswiki::AggregateIterator::::BEGIN@14Foswiki::AggregateIterator::BEGIN@14
0000s0sFoswiki::AggregateIterator::::hasNextFoswiki::AggregateIterator::hasNext
0000s0sFoswiki::AggregateIterator::::newFoswiki::AggregateIterator::new
0000s0sFoswiki::AggregateIterator::::nextFoswiki::AggregateIterator::next
0000s0sFoswiki::AggregateIterator::::uniqueFoswiki::AggregateIterator::unique
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;
13226µs240µs
# spent 28µs (15+12) within Foswiki::AggregateIterator::BEGIN@13 which was called: # once (15µs+12µs) by Foswiki::Users::BEGIN@63 at line 13
use strict;
# spent 28µs making 1 call to Foswiki::AggregateIterator::BEGIN@13 # spent 12µs making 1 call to strict::import
14222µs218µs
# spent 13µs (8+5) within Foswiki::AggregateIterator::BEGIN@14 which was called: # once (8µs+5µs) by Foswiki::Users::BEGIN@63 at line 14
use warnings;
# spent 13µs making 1 call to Foswiki::AggregateIterator::BEGIN@14 # spent 5µs making 1 call to warnings::import
15
162370µs1375µs
# spent 375µs (270+105) within Foswiki::AggregateIterator::BEGIN@16 which was called: # once (270µs+105µs) by Foswiki::Users::BEGIN@63 at line 16
use Foswiki::Iterator ();
# spent 375µs making 1 call to Foswiki::AggregateIterator::BEGIN@16
1718µ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
31sub new {
32 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
57sub hasNext {
58 my ($this) = @_;
59 return 1 if $this->{next};
60 my $n;
61 do {
62 unless ( $this->{list} ) {
63 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 }
70 if ( $this->{list}->hasNext() ) {
71 $n = $this->{list}->next();
72 }
73 else {
74 $this->{list} = undef; #goto next iterator
75 }
76 } while ( !$this->{list}
77 || ( $this->{filter} && !&{ $this->{filter} }($n) )
78 || ( $this->{unique} && !$this->unique($n) ) );
79 $this->{next} = $n;
80 return 1;
81}
82
83sub unique {
84 my ( $this, $value ) = @_;
85
86 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
112sub next {
113 my $this = shift;
114 $this->hasNext();
115 my $n = $this->{next};
116 $this->{next} = undef;
117 $n = &{ $this->{process} }($n) if $this->{process};
118
119 #print STDERR "next - $n \n";
120 return $n;
121}
122
12313µs1;
124__END__