| Filename | /home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/x86_64-linux/List/MoreUtils.pm |
| Statements | Executed 23 statements in 412µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 77849 | 1 | 1 | 333ms | 333ms | List::MoreUtils::uniq (xsub) |
| 1 | 1 | 1 | 78µs | 78µs | List::MoreUtils::bootstrap (xsub) |
| 1 | 1 | 1 | 39µs | 39µs | List::MoreUtils::BEGIN@3 |
| 1 | 1 | 1 | 13µs | 120µs | List::MoreUtils::BEGIN@8 |
| 1 | 1 | 1 | 12µs | 17µs | List::MoreUtils::BEGIN@4 |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package List::MoreUtils; | ||||
| 2 | |||||
| 3 | 2 | 44µs | 1 | 39µs | # spent 39µs within List::MoreUtils::BEGIN@3 which was called:
# once (39µs+0s) by Hailo::Engine::Default::BEGIN@6 at line 3 # spent 39µs making 1 call to List::MoreUtils::BEGIN@3 |
| 4 | 2 | 34µs | 2 | 21µs | # spent 17µs (12+5) within List::MoreUtils::BEGIN@4 which was called:
# once (12µs+5µs) by Hailo::Engine::Default::BEGIN@6 at line 4 # spent 17µs making 1 call to List::MoreUtils::BEGIN@4
# spent 5µs making 1 call to strict::import |
| 5 | |||||
| 6 | 1 | 2µs | require Exporter; | ||
| 7 | 1 | 2µs | require DynaLoader; | ||
| 8 | 2 | 272µs | 2 | 228µs | # spent 120µs (13+107) within List::MoreUtils::BEGIN@8 which was called:
# once (13µs+107µs) by Hailo::Engine::Default::BEGIN@6 at line 8 # spent 120µs making 1 call to List::MoreUtils::BEGIN@8
# spent 107µs making 1 call to vars::import |
| 9 | 1 | 8µs | @ISA = qw(Exporter DynaLoader); | ||
| 10 | |||||
| 11 | 1 | 6µs | %EXPORT_TAGS = ( | ||
| 12 | all => [ qw(any all none notall true false firstidx first_index lastidx | ||||
| 13 | last_index insert_after insert_after_string apply after after_incl before | ||||
| 14 | before_incl indexes firstval first_value lastval last_value each_array | ||||
| 15 | each_arrayref pairwise natatime mesh zip uniq minmax part) ], | ||||
| 16 | ); | ||||
| 17 | |||||
| 18 | 1 | 8µs | @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | ||
| 19 | |||||
| 20 | 1 | 800ns | $VERSION = '0.22'; | ||
| 21 | |||||
| 22 | 1 | 3µs | eval { | ||
| 23 | 1 | 1µs | local $ENV{PERL_DL_NONLAZY} = 0 if $ENV{PERL_DL_NONLAZY}; | ||
| 24 | 1 | 9µs | 1 | 389µs | bootstrap List::MoreUtils $VERSION; # spent 389µs making 1 call to DynaLoader::bootstrap |
| 25 | 1 | 1µs | 1; | ||
| 26 | } if not $ENV{LIST_MOREUTILS_PP}; | ||||
| 27 | |||||
| 28 | 1 | 1µs | eval <<'EOP' if not defined &any; | ||
| 29 | |||||
| 30 | sub any (&@) { | ||||
| 31 | my $f = shift; | ||||
| 32 | return if ! @_; | ||||
| 33 | for (@_) { | ||||
| 34 | return 1 if $f->(); | ||||
| 35 | } | ||||
| 36 | return 0; | ||||
| 37 | } | ||||
| 38 | |||||
| 39 | sub all (&@) { | ||||
| 40 | my $f = shift; | ||||
| 41 | return if ! @_; | ||||
| 42 | for (@_) { | ||||
| 43 | return 0 if ! $f->(); | ||||
| 44 | } | ||||
| 45 | return 1; | ||||
| 46 | } | ||||
| 47 | |||||
| 48 | sub none (&@) { | ||||
| 49 | my $f = shift; | ||||
| 50 | return if ! @_; | ||||
| 51 | for (@_) { | ||||
| 52 | return 0 if $f->(); | ||||
| 53 | } | ||||
| 54 | return 1; | ||||
| 55 | } | ||||
| 56 | |||||
| 57 | sub notall (&@) { | ||||
| 58 | my $f = shift; | ||||
| 59 | return if ! @_; | ||||
| 60 | for (@_) { | ||||
| 61 | return 1 if ! $f->(); | ||||
| 62 | } | ||||
| 63 | return 0; | ||||
| 64 | } | ||||
| 65 | |||||
| 66 | sub true (&@) { | ||||
| 67 | my $f = shift; | ||||
| 68 | my $count = 0; | ||||
| 69 | for (@_) { | ||||
| 70 | $count++ if $f->(); | ||||
| 71 | } | ||||
| 72 | return $count; | ||||
| 73 | } | ||||
| 74 | |||||
| 75 | sub false (&@) { | ||||
| 76 | my $f = shift; | ||||
| 77 | my $count = 0; | ||||
| 78 | for (@_) { | ||||
| 79 | $count++ if ! $f->(); | ||||
| 80 | } | ||||
| 81 | return $count; | ||||
| 82 | } | ||||
| 83 | |||||
| 84 | sub firstidx (&@) { | ||||
| 85 | my $f = shift; | ||||
| 86 | for my $i (0 .. $#_) { | ||||
| 87 | local *_ = \$_[$i]; | ||||
| 88 | return $i if $f->(); | ||||
| 89 | } | ||||
| 90 | return -1; | ||||
| 91 | } | ||||
| 92 | |||||
| 93 | sub lastidx (&@) { | ||||
| 94 | my $f = shift; | ||||
| 95 | for my $i (reverse 0 .. $#_) { | ||||
| 96 | local *_ = \$_[$i]; | ||||
| 97 | return $i if $f->(); | ||||
| 98 | } | ||||
| 99 | return -1; | ||||
| 100 | } | ||||
| 101 | |||||
| 102 | sub insert_after (&$\@) { | ||||
| 103 | my ($code, $val, $list) = @_; | ||||
| 104 | my $c = -1; | ||||
| 105 | local *_; | ||||
| 106 | for my $i (0 .. $#$list) { | ||||
| 107 | $_ = $list->[$i]; | ||||
| 108 | $c = $i, last if $code->(); | ||||
| 109 | } | ||||
| 110 | @$list = (@{$list}[0..$c], $val, @{$list}[$c+1..$#$list]) and return 1 if $c != -1; | ||||
| 111 | return 0; | ||||
| 112 | } | ||||
| 113 | |||||
| 114 | sub insert_after_string ($$\@) { | ||||
| 115 | my ($string, $val, $list) = @_; | ||||
| 116 | my $c = -1; | ||||
| 117 | for my $i (0 .. $#$list) { | ||||
| 118 | local $^W = 0; | ||||
| 119 | $c = $i, last if $string eq $list->[$i]; | ||||
| 120 | } | ||||
| 121 | @$list = (@{$list}[0..$c], $val, @{$list}[$c+1..$#$list]) and return 1 if $c != -1; | ||||
| 122 | return 0; | ||||
| 123 | } | ||||
| 124 | |||||
| 125 | sub apply (&@) { | ||||
| 126 | my $action = shift; | ||||
| 127 | &$action for my @values = @_; | ||||
| 128 | wantarray ? @values : $values[-1]; | ||||
| 129 | } | ||||
| 130 | |||||
| 131 | sub after (&@) | ||||
| 132 | { | ||||
| 133 | my $test = shift; | ||||
| 134 | my $started; | ||||
| 135 | my $lag; | ||||
| 136 | grep $started ||= do { my $x=$lag; $lag=$test->(); $x}, @_; | ||||
| 137 | } | ||||
| 138 | |||||
| 139 | sub after_incl (&@) | ||||
| 140 | { | ||||
| 141 | my $test = shift; | ||||
| 142 | my $started; | ||||
| 143 | grep $started ||= $test->(), @_; | ||||
| 144 | } | ||||
| 145 | |||||
| 146 | sub before (&@) | ||||
| 147 | { | ||||
| 148 | my $test = shift; | ||||
| 149 | my $keepgoing=1; | ||||
| 150 | grep $keepgoing &&= !$test->(), @_; | ||||
| 151 | } | ||||
| 152 | |||||
| 153 | sub before_incl (&@) | ||||
| 154 | { | ||||
| 155 | my $test = shift; | ||||
| 156 | my $keepgoing=1; | ||||
| 157 | my $lag=1; | ||||
| 158 | grep $keepgoing &&= do { my $x=$lag; $lag=!$test->(); $x}, @_; | ||||
| 159 | } | ||||
| 160 | |||||
| 161 | sub indexes (&@) | ||||
| 162 | { | ||||
| 163 | my $test = shift; | ||||
| 164 | grep {local *_=\$_[$_]; $test->()} 0..$#_; | ||||
| 165 | } | ||||
| 166 | |||||
| 167 | sub lastval (&@) | ||||
| 168 | { | ||||
| 169 | my $test = shift; | ||||
| 170 | my $ix; | ||||
| 171 | for ($ix=$#_; $ix>=0; $ix--) | ||||
| 172 | { | ||||
| 173 | local *_ = \$_[$ix]; | ||||
| 174 | my $testval = $test->(); | ||||
| 175 | $_[$ix] = $_; # simulate $_ as alias | ||||
| 176 | return $_ if $testval; | ||||
| 177 | } | ||||
| 178 | return undef; | ||||
| 179 | } | ||||
| 180 | |||||
| 181 | sub firstval (&@) | ||||
| 182 | { | ||||
| 183 | my $test = shift; | ||||
| 184 | foreach (@_) | ||||
| 185 | { | ||||
| 186 | return $_ if $test->(); | ||||
| 187 | } | ||||
| 188 | return undef; | ||||
| 189 | } | ||||
| 190 | |||||
| 191 | sub pairwise(&\@\@) | ||||
| 192 | { | ||||
| 193 | my $op = shift; | ||||
| 194 | use vars qw/@A @B/; | ||||
| 195 | local (*A, *B) = @_; # syms for caller's input arrays | ||||
| 196 | |||||
| 197 | # Localise $a, $b | ||||
| 198 | my ($caller_a, $caller_b) = do | ||||
| 199 | { | ||||
| 200 | my $pkg = caller(); | ||||
| 201 | no strict 'refs'; | ||||
| 202 | \*{$pkg.'::a'}, \*{$pkg.'::b'}; | ||||
| 203 | }; | ||||
| 204 | |||||
| 205 | my $limit = $#A > $#B? $#A : $#B; # loop iteration limit | ||||
| 206 | |||||
| 207 | local(*$caller_a, *$caller_b); | ||||
| 208 | map # This map expression is also the return value. | ||||
| 209 | { | ||||
| 210 | # assign to $a, $b as refs to caller's array elements | ||||
| 211 | (*$caller_a, *$caller_b) = \($A[$_], $B[$_]); | ||||
| 212 | $op->(); # perform the transformation | ||||
| 213 | } 0 .. $limit; | ||||
| 214 | } | ||||
| 215 | |||||
| 216 | sub each_array (\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@) | ||||
| 217 | { | ||||
| 218 | return each_arrayref(@_); | ||||
| 219 | } | ||||
| 220 | |||||
| 221 | sub each_arrayref | ||||
| 222 | { | ||||
| 223 | my @arr_list = @_; # The list of references to the arrays | ||||
| 224 | my $index = 0; # Which one the caller will get next | ||||
| 225 | my $max_num = 0; # Number of elements in longest array | ||||
| 226 | |||||
| 227 | # Get the length of the longest input array | ||||
| 228 | foreach (@arr_list) | ||||
| 229 | { | ||||
| 230 | unless (ref($_) eq 'ARRAY') | ||||
| 231 | { | ||||
| 232 | require Carp; | ||||
| 233 | Carp::croak "each_arrayref: argument is not an array reference\n"; | ||||
| 234 | } | ||||
| 235 | $max_num = @$_ if @$_ > $max_num; | ||||
| 236 | } | ||||
| 237 | |||||
| 238 | # Return the iterator as a closure wrt the above variables. | ||||
| 239 | return sub | ||||
| 240 | { | ||||
| 241 | if (@_) | ||||
| 242 | { | ||||
| 243 | my $method = shift; | ||||
| 244 | if ($method eq 'index') | ||||
| 245 | { | ||||
| 246 | # Return current (last fetched) index | ||||
| 247 | return undef if $index == 0 || $index > $max_num; | ||||
| 248 | return $index-1; | ||||
| 249 | } | ||||
| 250 | else | ||||
| 251 | { | ||||
| 252 | require Carp; | ||||
| 253 | Carp::croak "each_array: unknown argument '$method' passed to iterator."; | ||||
| 254 | } | ||||
| 255 | } | ||||
| 256 | |||||
| 257 | return if $index >= $max_num; # No more elements to return | ||||
| 258 | my $i = $index++; | ||||
| 259 | return map $_->[$i], @arr_list; # Return ith elements | ||||
| 260 | } | ||||
| 261 | } | ||||
| 262 | |||||
| 263 | sub natatime ($@) | ||||
| 264 | { | ||||
| 265 | my $n = shift; | ||||
| 266 | my @list = @_; | ||||
| 267 | |||||
| 268 | return sub | ||||
| 269 | { | ||||
| 270 | return splice @list, 0, $n; | ||||
| 271 | } | ||||
| 272 | } | ||||
| 273 | |||||
| 274 | sub mesh (\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@) { | ||||
| 275 | my $max = -1; | ||||
| 276 | $max < $#$_ && ($max = $#$_) for @_; | ||||
| 277 | |||||
| 278 | map { my $ix = $_; map $_->[$ix], @_; } 0..$max; | ||||
| 279 | } | ||||
| 280 | |||||
| 281 | sub uniq (@) { | ||||
| 282 | my %h; | ||||
| 283 | map { $h{$_}++ == 0 ? $_ : () } @_; | ||||
| 284 | } | ||||
| 285 | |||||
| 286 | sub minmax (@) { | ||||
| 287 | return if ! @_; | ||||
| 288 | my $min = my $max = $_[0]; | ||||
| 289 | |||||
| 290 | for (my $i = 1; $i < @_; $i += 2) { | ||||
| 291 | if ($_[$i-1] <= $_[$i]) { | ||||
| 292 | $min = $_[$i-1] if $min > $_[$i-1]; | ||||
| 293 | $max = $_[$i] if $max < $_[$i]; | ||||
| 294 | } else { | ||||
| 295 | $min = $_[$i] if $min > $_[$i]; | ||||
| 296 | $max = $_[$i-1] if $max < $_[$i-1]; | ||||
| 297 | } | ||||
| 298 | } | ||||
| 299 | |||||
| 300 | if (@_ & 1) { | ||||
| 301 | my $i = $#_; | ||||
| 302 | if ($_[$i-1] <= $_[$i]) { | ||||
| 303 | $min = $_[$i-1] if $min > $_[$i-1]; | ||||
| 304 | $max = $_[$i] if $max < $_[$i]; | ||||
| 305 | } else { | ||||
| 306 | $min = $_[$i] if $min > $_[$i]; | ||||
| 307 | $max = $_[$i-1] if $max < $_[$i-1]; | ||||
| 308 | } | ||||
| 309 | } | ||||
| 310 | |||||
| 311 | return ($min, $max); | ||||
| 312 | } | ||||
| 313 | |||||
| 314 | sub part(&@) { | ||||
| 315 | my ($code, @list) = @_; | ||||
| 316 | my @parts; | ||||
| 317 | push @{ $parts[$code->($_)] }, $_ for @list; | ||||
| 318 | return @parts; | ||||
| 319 | } | ||||
| 320 | |||||
| 321 | sub _XScompiled { | ||||
| 322 | return 0; | ||||
| 323 | } | ||||
| 324 | |||||
| 325 | EOP | ||||
| 326 | |||||
| 327 | 1 | 2µs | *first_index = \&firstidx; | ||
| 328 | 1 | 900ns | *last_index = \&lastidx; | ||
| 329 | 1 | 1µs | *first_value = \&firstval; | ||
| 330 | 1 | 1µs | *last_value = \&lastval; | ||
| 331 | 1 | 1µs | *zip = \&mesh; | ||
| 332 | |||||
| 333 | 1 | 14µs | 1; | ||
| 334 | __END__ | ||||
# spent 78µs within List::MoreUtils::bootstrap which was called:
# once (78µs+0s) by DynaLoader::bootstrap at line 219 of DynaLoader.pm | |||||
# spent 333ms within List::MoreUtils::uniq which was called 77849 times, avg 4µs/call:
# 77849 times (333ms+0s) by Hailo::Engine::Default::learn at line 117 of lib/Hailo/Engine/Default.pm, avg 4µs/call |