Filename | /var/www/foswiki11/lib/Foswiki/Iterator.pm |
Statements | Executed 56 statements in 9.17ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
40 | 1 | 1 | 702µs | 798µs | reset | Foswiki::Iterator::
1 | 1 | 1 | 33µs | 52µs | all | Foswiki::Iterator::
1 | 1 | 1 | 12µs | 30µs | BEGIN@21 | Foswiki::Iterator::
1 | 1 | 1 | 11µs | 16µs | BEGIN@22 | Foswiki::Iterator::
1 | 1 | 1 | 8µs | 24µs | BEGIN@23 | Foswiki::Iterator::
1 | 1 | 1 | 7µs | 36µs | BEGIN@26 | 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 | 25µs | 2 | 47µs | # spent 30µs (12+18) within Foswiki::Iterator::BEGIN@21 which was called:
# once (12µs+18µs) by Foswiki::AggregateIterator::BEGIN@16 at line 21 # spent 30µs making 1 call to Foswiki::Iterator::BEGIN@21
# spent 18µs making 1 call to strict::import |
22 | 2 | 23µs | 2 | 20µs | # spent 16µs (11+5) within Foswiki::Iterator::BEGIN@22 which was called:
# once (11µs+5µs) by Foswiki::AggregateIterator::BEGIN@16 at line 22 # spent 16µs making 1 call to Foswiki::Iterator::BEGIN@22
# spent 5µs making 1 call to warnings::import |
23 | 2 | 26µs | 2 | 40µs | # spent 24µs (8+16) within Foswiki::Iterator::BEGIN@23 which was called:
# once (8µs+16µs) by Foswiki::AggregateIterator::BEGIN@16 at line 23 # spent 24µs making 1 call to Foswiki::Iterator::BEGIN@23
# spent 16µs making 1 call to Assert::import |
24 | |||||
25 | #debug Iterators | ||||
26 | 2 | 149µs | 2 | 64µs | # spent 36µs (7+29) within Foswiki::Iterator::BEGIN@26 which was called:
# once (7µs+29µs) by Foswiki::AggregateIterator::BEGIN@16 at line 26 # spent 36µs making 1 call to Foswiki::Iterator::BEGIN@26
# spent 29µs making 1 call to constant::import |
27 | |||||
28 | =begin TML | ||||
29 | |||||
30 | ---++ hasNext() -> $boolean | ||||
31 | |||||
32 | Returns true if the iterator has more items, or false when the iterator | ||||
33 | is exhausted. | ||||
34 | |||||
35 | =cut | ||||
36 | |||||
37 | sub hasNext { ASSERT('Pure virtual function called') if DEBUG; } | ||||
38 | |||||
39 | =begin TML | ||||
40 | |||||
41 | ---++ next() -> $data | ||||
42 | |||||
43 | Return the next data in the iteration. | ||||
44 | |||||
45 | The data may be any type. | ||||
46 | |||||
47 | The iterator object can be customised to pre- and post-process entries from | ||||
48 | the list before returning them. This is done by setting two fields in the | ||||
49 | iterator object: | ||||
50 | |||||
51 | * ={filter}= can be defined to be a sub that filters each entry. The entry | ||||
52 | will be ignored (next() will not return it) if the filter returns false. | ||||
53 | * ={process}= can be defined to be a sub to process each entry before it | ||||
54 | is returned by next. The value returned from next is the value returned | ||||
55 | by the process function. | ||||
56 | |||||
57 | =cut | ||||
58 | |||||
59 | sub next { ASSERT('Pure virtual function called') if DEBUG; } | ||||
60 | |||||
61 | =begin TML | ||||
62 | |||||
63 | ---++ reset() -> $boolean | ||||
64 | |||||
65 | resets the iterator to the begining - returns false if it can't | ||||
66 | |||||
67 | =cut | ||||
68 | |||||
69 | 40 | 8.93ms | 40 | 96µs | # spent 798µs (702+96) within Foswiki::Iterator::reset which was called 40 times, avg 20µs/call:
# 40 times (702µs+96µs) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 208 of /var/www/foswiki11/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 20µs/call # spent 96µs making 40 calls to Assert::ASSERTS_OFF, avg 2µs/call |
70 | |||||
71 | =begin TML | ||||
72 | |||||
73 | ---++ ObjectMethod all() -> @list | ||||
74 | |||||
75 | Exhaust the iterator. Return all remaining elements in the iteration | ||||
76 | as a list. The returned list should be considered to be immutable. | ||||
77 | |||||
78 | The default implementation simply runs the iterator to its end. | ||||
79 | |||||
80 | =cut | ||||
81 | |||||
82 | # spent 52µs (33+19) within Foswiki::Iterator::all which was called:
# once (33µs+19µs) by Foswiki::UI::View::revisionsAround at line 441 of /var/www/foswiki11/lib/Foswiki/UI/View.pm | ||||
83 | 1 | 1µs | my ($this) = @_; | ||
84 | 1 | 400ns | my @remains; | ||
85 | 1 | 3µs | 1 | 6µs | while ( $this->hasNext() ) { # spent 6µs making 1 call to Foswiki::Iterator::NumberRangeIterator::hasNext |
86 | 3 | 10µs | 6 | 13µs | push( @remains, $this->next() ); # spent 8µs making 3 calls to Foswiki::Iterator::NumberRangeIterator::next, avg 3µs/call
# spent 5µs making 3 calls to Foswiki::Iterator::NumberRangeIterator::hasNext, avg 2µs/call |
87 | } | ||||
88 | 1 | 6µs | return @remains; | ||
89 | } | ||||
90 | |||||
91 | 1 | 2µs | 1; | ||
92 | __END__ |