Filename | /var/www/foswikidev/core/lib/Foswiki/Iterator.pm |
Statements | Executed 57 statements in 625µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
40 | 1 | 1 | 244µs | 244µs | reset | Foswiki::Iterator::
1 | 1 | 1 | 24µs | 42µs | all | Foswiki::Iterator::
1 | 1 | 1 | 12µs | 36µs | BEGIN@23 | Foswiki::Iterator::
1 | 1 | 1 | 12µs | 24µs | BEGIN@21 | Foswiki::Iterator::
1 | 1 | 1 | 8µs | 42µs | BEGIN@26 | Foswiki::Iterator::
1 | 1 | 1 | 8µs | 11µs | BEGIN@22 | Foswiki::Iterator::
1 | 1 | 1 | 4µs | 4µs | BEGIN@28 | Foswiki::Iterator::
0 | 0 | 0 | 0s | 0s | hasNext | Foswiki::Iterator::
0 | 0 | 0 | 0s | 0s | next | Foswiki::Iterator::
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::Iterator | ||||
6 | |||||
7 | This class cannot be instantiated on its own - it is an interface | ||||
8 | specification for iterators. See http://en.wikipedia.org/wiki/Iterator_Pattern | ||||
9 | for more information on the iterator pattern. | ||||
10 | |||||
11 | The interface only supports forward iteration. Subclasses should use this | ||||
12 | as their base class (so that =$it->isa("Foswiki::Iterator")= returns true), | ||||
13 | and must implement =hasNext= and =next= per the specification below. | ||||
14 | |||||
15 | See Foswiki::ListIterator for an example implementation. | ||||
16 | |||||
17 | =cut | ||||
18 | |||||
19 | package Foswiki::Iterator; | ||||
20 | |||||
21 | 2 | 24µs | 2 | 35µs | # spent 24µs (12+11) within Foswiki::Iterator::BEGIN@21 which was called:
# once (12µs+11µs) by Foswiki::AggregateIterator::BEGIN@16 at line 21 # spent 24µs making 1 call to Foswiki::Iterator::BEGIN@21
# spent 12µs making 1 call to strict::import |
22 | 2 | 21µs | 2 | 15µs | # spent 11µs (8+4) within Foswiki::Iterator::BEGIN@22 which was called:
# once (8µs+4µs) by Foswiki::AggregateIterator::BEGIN@16 at line 22 # spent 11µs making 1 call to Foswiki::Iterator::BEGIN@22
# spent 4µs making 1 call to warnings::import |
23 | 2 | 28µs | 2 | 59µs | # spent 36µs (12+23) within Foswiki::Iterator::BEGIN@23 which was called:
# once (12µs+23µs) by Foswiki::AggregateIterator::BEGIN@16 at line 23 # spent 36µs making 1 call to Foswiki::Iterator::BEGIN@23
# spent 23µs making 1 call to Exporter::import |
24 | |||||
25 | #debug Iterators | ||||
26 | 2 | 50µs | 2 | 76µs | # spent 42µs (8+34) within Foswiki::Iterator::BEGIN@26 which was called:
# once (8µs+34µs) by Foswiki::AggregateIterator::BEGIN@16 at line 26 # spent 42µs making 1 call to Foswiki::Iterator::BEGIN@26
# spent 34µs making 1 call to constant::import |
27 | |||||
28 | # spent 4µs within Foswiki::Iterator::BEGIN@28 which was called:
# once (4µs+0s) by Foswiki::AggregateIterator::BEGIN@16 at line 33 | ||||
29 | 1 | 5µs | if ( $Foswiki::cfg{UseLocale} ) { | ||
30 | require locale; | ||||
31 | import locale(); | ||||
32 | } | ||||
33 | 1 | 150µs | 1 | 4µs | } # spent 4µs making 1 call to Foswiki::Iterator::BEGIN@28 |
34 | |||||
35 | =begin TML | ||||
36 | |||||
37 | ---++ hasNext() -> $boolean | ||||
38 | |||||
39 | Returns true if the iterator has more items, or false when the iterator | ||||
40 | is exhausted. | ||||
41 | |||||
42 | =cut | ||||
43 | |||||
44 | sub hasNext { ASSERT('Pure virtual function called') if DEBUG; } | ||||
45 | |||||
46 | =begin TML | ||||
47 | |||||
48 | ---++ next() -> $data | ||||
49 | |||||
50 | Return the next data in the iteration. | ||||
51 | |||||
52 | The data may be any type. | ||||
53 | |||||
54 | The iterator object can be customised to pre- and post-process entries from | ||||
55 | the list before returning them. This is done by setting two fields in the | ||||
56 | iterator object: | ||||
57 | |||||
58 | * ={filter}= can be defined to be a sub that filters each entry. The entry | ||||
59 | will be ignored (next() will not return it) if the filter returns false. | ||||
60 | * ={process}= can be defined to be a sub to process each entry before it | ||||
61 | is returned by next. The value returned from next is the value returned | ||||
62 | by the process function. | ||||
63 | |||||
64 | =cut | ||||
65 | |||||
66 | sub next { ASSERT('Pure virtual function called') if DEBUG; } | ||||
67 | |||||
68 | =begin TML | ||||
69 | |||||
70 | ---++ reset() -> $boolean | ||||
71 | |||||
72 | resets the iterator to the begining - returns false if it can't | ||||
73 | |||||
74 | =cut | ||||
75 | |||||
76 | 40 | 326µs | # spent 244µs within Foswiki::Iterator::reset which was called 40 times, avg 6µs/call:
# 40 times (244µs+0s) by Foswiki::Iterator::FilterIterator::reset at line 137 of /var/www/foswikidev/core/lib/Foswiki/Iterator/FilterIterator.pm, avg 6µs/call | ||
77 | |||||
78 | =begin TML | ||||
79 | |||||
80 | ---++ ObjectMethod all() -> @list | ||||
81 | |||||
82 | Exhaust the iterator. Return all remaining elements in the iteration | ||||
83 | as a list. The returned list should be considered to be immutable. | ||||
84 | |||||
85 | The default implementation simply runs the iterator to its end. | ||||
86 | |||||
87 | =cut | ||||
88 | |||||
89 | # spent 42µs (24+18) within Foswiki::Iterator::all which was called:
# once (24µs+18µs) by Foswiki::UI::View::revisionsAround at line 508 of /var/www/foswikidev/core/lib/Foswiki/UI/View.pm | ||||
90 | 1 | 1µs | my ($this) = @_; | ||
91 | 1 | 500ns | my @remains; | ||
92 | 1 | 7µs | 1 | 9µs | while ( $this->hasNext() ) { # spent 9µs making 1 call to Foswiki::Iterator::NumberRangeIterator::hasNext |
93 | 3 | 7µs | 6 | 10µs | push( @remains, $this->next() ); # spent 5µs making 3 calls to Foswiki::Iterator::NumberRangeIterator::next, avg 2µs/call
# spent 4µs making 3 calls to Foswiki::Iterator::NumberRangeIterator::hasNext, avg 2µs/call |
94 | } | ||||
95 | 1 | 4µs | return @remains; | ||
96 | } | ||||
97 | |||||
98 | 1 | 2µs | 1; | ||
99 | __END__ |