Filename | /var/www/foswikidev/core/lib/Foswiki/Iterator/MergeEventIterator.pm |
Statements | Executed 10 statements in 335µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 13µs | 25µs | BEGIN@4 | Foswiki::Iterator::MergeEventIterator::
1 | 1 | 1 | 11µs | 15µs | BEGIN@5 | Foswiki::Iterator::MergeEventIterator::
1 | 1 | 1 | 10µs | 34µs | BEGIN@6 | Foswiki::Iterator::MergeEventIterator::
1 | 1 | 1 | 4µs | 4µs | BEGIN@8 | Foswiki::Iterator::MergeEventIterator::
0 | 0 | 0 | 0s | 0s | hasNext | Foswiki::Iterator::MergeEventIterator::
0 | 0 | 0 | 0s | 0s | new | Foswiki::Iterator::MergeEventIterator::
0 | 0 | 0 | 0s | 0s | next | Foswiki::Iterator::MergeEventIterator::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | package Foswiki::Iterator::MergeEventIterator; | ||||
3 | |||||
4 | 2 | 28µs | 2 | 37µs | # spent 25µs (13+12) within Foswiki::Iterator::MergeEventIterator::BEGIN@4 which was called:
# once (13µs+12µs) by Foswiki::Logger::PlainFile::BEGIN@38 at line 4 # spent 25µs making 1 call to Foswiki::Iterator::MergeEventIterator::BEGIN@4
# spent 12µs making 1 call to strict::import |
5 | 2 | 24µs | 2 | 19µs | # spent 15µs (11+4) within Foswiki::Iterator::MergeEventIterator::BEGIN@5 which was called:
# once (11µs+4µs) by Foswiki::Logger::PlainFile::BEGIN@38 at line 5 # spent 15µs making 1 call to Foswiki::Iterator::MergeEventIterator::BEGIN@5
# spent 4µs making 1 call to warnings::import |
6 | 2 | 45µs | 2 | 58µs | # spent 34µs (10+24) within Foswiki::Iterator::MergeEventIterator::BEGIN@6 which was called:
# once (10µs+24µs) by Foswiki::Logger::PlainFile::BEGIN@38 at line 6 # spent 34µs making 1 call to Foswiki::Iterator::MergeEventIterator::BEGIN@6
# spent 24µs making 1 call to Exporter::import |
7 | |||||
8 | # spent 4µs within Foswiki::Iterator::MergeEventIterator::BEGIN@8 which was called:
# once (4µs+0s) by Foswiki::Logger::PlainFile::BEGIN@38 at line 13 | ||||
9 | 1 | 6µs | if ( $Foswiki::cfg{UseLocale} ) { | ||
10 | require locale; | ||||
11 | import locale(); | ||||
12 | } | ||||
13 | 1 | 222µs | 1 | 4µs | } # spent 4µs making 1 call to Foswiki::Iterator::MergeEventIterator::BEGIN@8 |
14 | |||||
15 | =begin TML | ||||
16 | |||||
17 | ---++ =Foswiki::Iterator::MergeEventIterator= | ||||
18 | Private subclass of Foswiki::Iterator that | ||||
19 | * Is passed a array reference of a list of iterator arrays. | ||||
20 | * Scans across the list of iterators using snoopNext to find the iterator with the lowest timestamp | ||||
21 | * returns true to hasNext if any iterator has any records available. | ||||
22 | * returns the record with the lowest timestamp to the next() request. | ||||
23 | |||||
24 | =cut | ||||
25 | |||||
26 | 1 | 500ns | require Foswiki::Iterator; | ||
27 | 1 | 6µs | our @ISA = ('Foswiki::Iterator'); | ||
28 | |||||
29 | sub new { | ||||
30 | my ( $class, $list ) = @_; | ||||
31 | my $this = bless( | ||||
32 | { | ||||
33 | Itr_list_ref => $list, | ||||
34 | process => undef, | ||||
35 | filter => undef, | ||||
36 | next => undef, | ||||
37 | }, | ||||
38 | $class | ||||
39 | ); | ||||
40 | return $this; | ||||
41 | } | ||||
42 | |||||
43 | =begin TML | ||||
44 | |||||
45 | ---+++ ObjectMethod hasNext() -> $boolean | ||||
46 | Scans all the iterators to determine if any of them have a record available. | ||||
47 | |||||
48 | =cut | ||||
49 | |||||
50 | sub hasNext { | ||||
51 | my $this = shift; | ||||
52 | |||||
53 | foreach my $It ( @{ $this->{Itr_list_ref} } ) { | ||||
54 | return 1 if $It->hasNext(); | ||||
55 | } | ||||
56 | return 0; | ||||
57 | } | ||||
58 | |||||
59 | =begin TML | ||||
60 | |||||
61 | ---+++ ObjectMethod next() -> \$hash or @array | ||||
62 | Snoop all of the iterators to find the lowest timestamp record, and return the | ||||
63 | field hash, or field array, depending up on the requested API version. | ||||
64 | |||||
65 | =cut | ||||
66 | |||||
67 | sub next { | ||||
68 | my $this = shift; | ||||
69 | my $lowIt; | ||||
70 | my $lowest; | ||||
71 | |||||
72 | foreach my $It ( @{ $this->{Itr_list_ref} } ) { | ||||
73 | next unless $It->hasNext(); | ||||
74 | my $nextRec = @{ $It->snoopNext() }[0]; | ||||
75 | my $epoch = $nextRec->{epoch}; | ||||
76 | |||||
77 | if ( !defined $lowest || $epoch <= $lowest ) { | ||||
78 | $lowIt = $It; | ||||
79 | $lowest = $epoch; | ||||
80 | } | ||||
81 | } | ||||
82 | return $lowIt->next(); | ||||
83 | } | ||||
84 | |||||
85 | 1 | 3µs | 1; | ||
86 | __END__ |