← Index
NYTProf Performance Profile   « line view »
For rbm/rbm
  Run on Wed Feb 12 03:38:15 2020
Reported on Wed Feb 12 04:56:37 2020

Filename/usr/lib/x86_64-linux-gnu/perl5/5.28/Template/VMethods.pm
StatementsExecuted 31878 statements in 157ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
19911157.2ms77.9msTemplate::VMethods::::list_sortTemplate::VMethods::list_sort
39811133.8ms33.8msTemplate::VMethods::::text_substrTemplate::VMethods::text_substr
19911124.1ms24.1msTemplate::VMethods::::list_importTemplate::VMethods::list_import
19911120.7ms20.7msTemplate::VMethods::::CORE:sortTemplate::VMethods::CORE:sort (opcode)
11145µs47µsTemplate::VMethods::::BEGIN@24Template::VMethods::BEGIN@24
11111µs12µsTemplate::VMethods::::BEGIN@27Template::VMethods::BEGIN@27
11110µs25µsTemplate::VMethods::::BEGIN@469Template::VMethods::BEGIN@469
1118µs31µsTemplate::VMethods::::BEGIN@118Template::VMethods::BEGIN@118
1117µs55µsTemplate::VMethods::::BEGIN@26Template::VMethods::BEGIN@26
1116µs17µsTemplate::VMethods::::BEGIN@496Template::VMethods::BEGIN@496
1116µs21µsTemplate::VMethods::::BEGIN@25Template::VMethods::BEGIN@25
1116µs15µsTemplate::VMethods::::BEGIN@502Template::VMethods::BEGIN@502
1115µs15µsTemplate::VMethods::::BEGIN@124Template::VMethods::BEGIN@124
111600ns600nsTemplate::VMethods::::__ANON__Template::VMethods::__ANON__ (xsub)
0000s0sTemplate::VMethods::::__ANON__[:234]Template::VMethods::__ANON__[:234]
0000s0sTemplate::VMethods::::__ANON__[:606]Template::VMethods::__ANON__[:606]
0000s0sTemplate::VMethods::::_list_sort_make_keyTemplate::VMethods::_list_sort_make_key
0000s0sTemplate::VMethods::::hash_definedTemplate::VMethods::hash_defined
0000s0sTemplate::VMethods::::hash_deleteTemplate::VMethods::hash_delete
0000s0sTemplate::VMethods::::hash_eachTemplate::VMethods::hash_each
0000s0sTemplate::VMethods::::hash_emptyTemplate::VMethods::hash_empty
0000s0sTemplate::VMethods::::hash_existsTemplate::VMethods::hash_exists
0000s0sTemplate::VMethods::::hash_hashTemplate::VMethods::hash_hash
0000s0sTemplate::VMethods::::hash_importTemplate::VMethods::hash_import
0000s0sTemplate::VMethods::::hash_itemTemplate::VMethods::hash_item
0000s0sTemplate::VMethods::::hash_itemsTemplate::VMethods::hash_items
0000s0sTemplate::VMethods::::hash_keysTemplate::VMethods::hash_keys
0000s0sTemplate::VMethods::::hash_listTemplate::VMethods::hash_list
0000s0sTemplate::VMethods::::hash_nsortTemplate::VMethods::hash_nsort
0000s0sTemplate::VMethods::::hash_pairsTemplate::VMethods::hash_pairs
0000s0sTemplate::VMethods::::hash_sizeTemplate::VMethods::hash_size
0000s0sTemplate::VMethods::::hash_sortTemplate::VMethods::hash_sort
0000s0sTemplate::VMethods::::hash_valuesTemplate::VMethods::hash_values
0000s0sTemplate::VMethods::::list_definedTemplate::VMethods::list_defined
0000s0sTemplate::VMethods::::list_emptyTemplate::VMethods::list_empty
0000s0sTemplate::VMethods::::list_firstTemplate::VMethods::list_first
0000s0sTemplate::VMethods::::list_grepTemplate::VMethods::list_grep
0000s0sTemplate::VMethods::::list_hashTemplate::VMethods::list_hash
0000s0sTemplate::VMethods::::list_itemTemplate::VMethods::list_item
0000s0sTemplate::VMethods::::list_joinTemplate::VMethods::list_join
0000s0sTemplate::VMethods::::list_lastTemplate::VMethods::list_last
0000s0sTemplate::VMethods::::list_listTemplate::VMethods::list_list
0000s0sTemplate::VMethods::::list_maxTemplate::VMethods::list_max
0000s0sTemplate::VMethods::::list_mergeTemplate::VMethods::list_merge
0000s0sTemplate::VMethods::::list_nsortTemplate::VMethods::list_nsort
0000s0sTemplate::VMethods::::list_popTemplate::VMethods::list_pop
0000s0sTemplate::VMethods::::list_pushTemplate::VMethods::list_push
0000s0sTemplate::VMethods::::list_reverseTemplate::VMethods::list_reverse
0000s0sTemplate::VMethods::::list_shiftTemplate::VMethods::list_shift
0000s0sTemplate::VMethods::::list_sizeTemplate::VMethods::list_size
0000s0sTemplate::VMethods::::list_sliceTemplate::VMethods::list_slice
0000s0sTemplate::VMethods::::list_spliceTemplate::VMethods::list_splice
0000s0sTemplate::VMethods::::list_uniqueTemplate::VMethods::list_unique
0000s0sTemplate::VMethods::::list_unshiftTemplate::VMethods::list_unshift
0000s0sTemplate::VMethods::::root_decTemplate::VMethods::root_dec
0000s0sTemplate::VMethods::::root_incTemplate::VMethods::root_inc
0000s0sTemplate::VMethods::::text_chunkTemplate::VMethods::text_chunk
0000s0sTemplate::VMethods::::text_collapseTemplate::VMethods::text_collapse
0000s0sTemplate::VMethods::::text_definedTemplate::VMethods::text_defined
0000s0sTemplate::VMethods::::text_dquoteTemplate::VMethods::text_dquote
0000s0sTemplate::VMethods::::text_emptyTemplate::VMethods::text_empty
0000s0sTemplate::VMethods::::text_hashTemplate::VMethods::text_hash
0000s0sTemplate::VMethods::::text_itemTemplate::VMethods::text_item
0000s0sTemplate::VMethods::::text_lcfirstTemplate::VMethods::text_lcfirst
0000s0sTemplate::VMethods::::text_lengthTemplate::VMethods::text_length
0000s0sTemplate::VMethods::::text_listTemplate::VMethods::text_list
0000s0sTemplate::VMethods::::text_lowerTemplate::VMethods::text_lower
0000s0sTemplate::VMethods::::text_matchTemplate::VMethods::text_match
0000s0sTemplate::VMethods::::text_removeTemplate::VMethods::text_remove
0000s0sTemplate::VMethods::::text_repeatTemplate::VMethods::text_repeat
0000s0sTemplate::VMethods::::text_replaceTemplate::VMethods::text_replace
0000s0sTemplate::VMethods::::text_searchTemplate::VMethods::text_search
0000s0sTemplate::VMethods::::text_sizeTemplate::VMethods::text_size
0000s0sTemplate::VMethods::::text_splitTemplate::VMethods::text_split
0000s0sTemplate::VMethods::::text_squoteTemplate::VMethods::text_squote
0000s0sTemplate::VMethods::::text_trimTemplate::VMethods::text_trim
0000s0sTemplate::VMethods::::text_ucfirstTemplate::VMethods::text_ucfirst
0000s0sTemplate::VMethods::::text_upperTemplate::VMethods::text_upper
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1#============================================================= -*-Perl-*-
2#
3# Template::VMethods
4#
5# DESCRIPTION
6# Module defining virtual methods for the Template Toolkit
7#
8# AUTHOR
9# Andy Wardley <abw@wardley.org>
10#
11# COPYRIGHT
12# Copyright (C) 1996-2015 Andy Wardley. All Rights Reserved.
13#
14# This module is free software; you can redistribute it and/or
15# modify it under the same terms as Perl itself.
16#
17# REVISION
18# $Id$
19#
20#============================================================================
21
22package Template::VMethods;
23
24229µs250µs
# spent 47µs (45+2) within Template::VMethods::BEGIN@24 which was called: # once (45µs+2µs) by Template::Stash::BEGIN@24 at line 24
use strict;
# spent 47µs making 1 call to Template::VMethods::BEGIN@24 # spent 2µs making 1 call to strict::import
25224µs237µs
# spent 21µs (6+15) within Template::VMethods::BEGIN@25 which was called: # once (6µs+15µs) by Template::Stash::BEGIN@24 at line 25
use warnings;
# spent 21µs making 1 call to Template::VMethods::BEGIN@25 # spent 15µs making 1 call to warnings::import
26230µs2102µs
# spent 55µs (7+48) within Template::VMethods::BEGIN@26 which was called: # once (7µs+48µs) by Template::Stash::BEGIN@24 at line 26
use Scalar::Util qw( blessed looks_like_number );
# spent 55µs making 1 call to Template::VMethods::BEGIN@26 # spent 48µs making 1 call to Exporter::import
272411µs212µs
# spent 12µs (11+600ns) within Template::VMethods::BEGIN@27 which was called: # once (11µs+600ns) by Template::Stash::BEGIN@24 at line 27
use Template::Filters;
# spent 12µs making 1 call to Template::VMethods::BEGIN@27 # spent 600ns making 1 call to Template::VMethods::__ANON__
281400nsrequire Template::Stash;
29
301200nsour $VERSION = 2.16;
311200nsour $DEBUG = 0 unless defined $DEBUG;
321200nsour $PRIVATE = $Template::Stash::PRIVATE;
33
3412µsour $ROOT_VMETHODS = {
35 inc => \&root_inc,
36 dec => \&root_dec,
37};
38
39112µsour $TEXT_VMETHODS = {
40 item => \&text_item,
41 list => \&text_list,
42 hash => \&text_hash,
43 length => \&text_length,
44 size => \&text_size,
45 empty => \&text_empty,
46 defined => \&text_defined,
47 upper => \&text_upper,
48 lower => \&text_lower,
49 ucfirst => \&text_ucfirst,
50 lcfirst => \&text_lcfirst,
51 match => \&text_match,
52 search => \&text_search,
53 repeat => \&text_repeat,
54 replace => \&text_replace,
55 remove => \&text_remove,
56 split => \&text_split,
57 chunk => \&text_chunk,
58 substr => \&text_substr,
59 trim => \&text_trim,
60 collapse => \&text_collapse,
61 squote => \&text_squote,
62 dquote => \&text_dquote,
63 html => \&Template::Filters::html_filter,
64 xml => \&Template::Filters::xml_filter,
65};
66
6716µsour $HASH_VMETHODS = {
68 item => \&hash_item,
69 hash => \&hash_hash,
70 size => \&hash_size,
71 empty => \&hash_empty,
72 each => \&hash_each,
73 keys => \&hash_keys,
74 values => \&hash_values,
75 items => \&hash_items,
76 pairs => \&hash_pairs,
77 list => \&hash_list,
78 exists => \&hash_exists,
79 defined => \&hash_defined,
80 delete => \&hash_delete,
81 import => \&hash_import,
82 sort => \&hash_sort,
83 nsort => \&hash_nsort,
84};
85
8619µsour $LIST_VMETHODS = {
87 item => \&list_item,
88 list => \&list_list,
89 hash => \&list_hash,
90 push => \&list_push,
91 pop => \&list_pop,
92 unshift => \&list_unshift,
93 shift => \&list_shift,
94 max => \&list_max,
95 size => \&list_size,
96 empty => \&list_empty,
97 defined => \&list_defined,
98 first => \&list_first,
99 last => \&list_last,
100 reverse => \&list_reverse,
101 grep => \&list_grep,
102 join => \&list_join,
103 sort => \&list_sort,
104 nsort => \&list_nsort,
105 unique => \&list_unique,
106 import => \&list_import,
107 merge => \&list_merge,
108 slice => \&list_slice,
109 splice => \&list_splice,
110};
111
112
113#========================================================================
114# root virtual methods
115#========================================================================
116
117sub root_inc {
118241µs254µs
# spent 31µs (8+23) within Template::VMethods::BEGIN@118 which was called: # once (8µs+23µs) by Template::Stash::BEGIN@24 at line 118
no warnings;
# spent 31µs making 1 call to Template::VMethods::BEGIN@118 # spent 23µs making 1 call to warnings::unimport
119 my $item = shift;
120 ++$item;
121}
122
123sub root_dec {
12421.58ms224µs
# spent 15µs (5+10) within Template::VMethods::BEGIN@124 which was called: # once (5µs+10µs) by Template::Stash::BEGIN@24 at line 124
no warnings;
# spent 15µs making 1 call to Template::VMethods::BEGIN@124 # spent 10µs making 1 call to warnings::unimport
125 my $item = shift;
126 --$item;
127}
128
129
130#========================================================================
131# text virtual methods
132#========================================================================
133
134sub text_item {
135 $_[0];
136}
137
138sub text_list {
139 [ $_[0] ];
140}
141
142sub text_hash {
143 { value => $_[0] };
144}
145
146sub text_length {
147 length $_[0];
148}
149
150sub text_size {
151 return 1;
152}
153
154sub text_empty {
155 return 0 == text_length($_[0]) ? 1 : 0;
156}
157
158sub text_defined {
159 return 1;
160}
161
162sub text_upper {
163 return uc $_[0];
164}
165
166sub text_lower {
167 return lc $_[0];
168}
169
170sub text_ucfirst {
171 return ucfirst $_[0];
172}
173
174sub text_lcfirst {
175 return lcfirst $_[0];
176}
177
178sub text_trim {
179 for ($_[0]) {
180 s/^\s+//;
181 s/\s+$//;
182 }
183 return $_[0];
184}
185
186sub text_collapse {
187 for ($_[0]) {
188 s/^\s+//;
189 s/\s+$//;
190 s/\s+/ /g
191 }
192 return $_[0];
193}
194
195sub text_match {
196 my ($str, $search, $global) = @_;
197 return $str unless defined $str and defined $search;
198 my @matches = $global ? ($str =~ /$search/g)
199 : ($str =~ /$search/);
200 return @matches ? \@matches : '';
201}
202
203sub text_search {
204 my ($str, $pattern) = @_;
205 return $str unless defined $str and defined $pattern;
206 return $str =~ /$pattern/;
207}
208
209sub text_repeat {
210 my ($str, $count) = @_;
211 $str = '' unless defined $str;
212 return '' unless $count;
213 $count ||= 1;
214 return $str x $count;
215}
216
217sub text_replace {
218 my ($text, $pattern, $replace, $global) = @_;
219 $text = '' unless defined $text;
220 $pattern = '' unless defined $pattern;
221 $replace = '' unless defined $replace;
222 $global = 1 unless defined $global;
223
224 if ($replace =~ /\$\d+/) {
225 # replacement string may contain backrefs
226 my $expand = sub {
227 my ($chunk, $start, $end) = @_;
228 $chunk =~ s{ \\(\\|\$) | \$ (\d+) }{
229 $1 ? $1
230 : ($2 > $#$start || $2 == 0 || !defined $start->[$2]) ? ''
231 : substr($text, $start->[$2], $end->[$2] - $start->[$2]);
232 }exg;
233 $chunk;
234 };
235 if ($global) {
236 $text =~ s{$pattern}{ &$expand($replace, [@-], [@+]) }eg;
237 }
238 else {
239 $text =~ s{$pattern}{ &$expand($replace, [@-], [@+]) }e;
240 }
241 }
242 else {
243 if ($global) {
244 $text =~ s/$pattern/$replace/g;
245 }
246 else {
247 $text =~ s/$pattern/$replace/;
248 }
249 }
250 return $text;
251}
252
253sub text_remove {
254 my ($str, $search) = @_;
255 return $str unless defined $str and defined $search;
256 $str =~ s/$search//g;
257 return $str;
258}
259
260sub text_split {
261 my ($str, $split, $limit) = @_;
262 $str = '' unless defined $str;
263
264 # For versions of Perl prior to 5.18 we have to be very careful about
265 # spelling out each possible combination of arguments because split()
266 # is very sensitive to them, for example C<split(' ', ...)> behaves
267 # differently to C<$space=' '; split($space, ...)>. Test 33 of
268 # vmethods/text.t depends on this behaviour.
269
270 if ($] < 5.018) {
271 if (defined $limit) {
272 return [ defined $split
273 ? split($split, $str, $limit)
274 : split(' ', $str, $limit) ];
275 }
276 else {
277 return [ defined $split
278 ? split($split, $str)
279 : split(' ', $str) ];
280 }
281 }
282
283 # split's behavior changed in Perl 5.18.0 making this:
284 # C<$space=' '; split($space, ...)>
285 # behave the same as this:
286 # C<split(' ', ...)>
287 # qr// behaves the same, so use that for user-defined split.
288
289 my $split_re;
290 if (defined $split) {
291 eval {
292 $split_re = qr/$split/;
293 };
294 }
295 $split_re = ' ' unless defined $split_re;
296 $limit ||= 0;
297 return [split($split_re, $str, $limit)];
298}
299
300sub text_chunk {
301 my ($string, $size) = @_;
302 my @list;
303 $size ||= 1;
304 if ($size < 0) {
305 # sexeger! It's faster to reverse the string, search
306 # it from the front and then reverse the output than to
307 # search it from the end, believe it nor not!
308 $string = reverse $string;
309 $size = -$size;
310 unshift(@list, scalar reverse $1)
311 while ($string =~ /((.{$size})|(.+))/g);
312 }
313 else {
314 push(@list, $1) while ($string =~ /((.{$size})|(.+))/g);
315 }
316 return \@list;
317}
318
319
# spent 33.8ms within Template::VMethods::text_substr which was called 3981 times, avg 8µs/call: # 3981 times (33.8ms+0s) by Template::Stash::XS::get at line 1 of /root/tor-browser-build/input text, avg 8µs/call
sub text_substr {
32039814.53ms my ($text, $offset, $length, $replacement) = @_;
32139813.38ms $offset ||= 0;
322
32339812.86ms if(defined $length) {
32439812.21ms if (defined $replacement) {
325 substr( $text, $offset, $length, $replacement );
326 return $text;
327 }
328 else {
329398138.5ms return substr( $text, $offset, $length );
330 }
331 }
332 else {
333 return substr( $text, $offset );
334 }
335}
336
337sub text_squote {
338 my $text = shift;
339 for ($text) {
340 s/(['\\])/\\$1/g;
341 }
342 return $text;
343}
344
345sub text_dquote {
346 my $text = shift;
347 for ($text) {
348 s/(["\\])/\\$1/g;
349 s/\n/\\n/g;
350 }
351 return $text;
352}
353
354#========================================================================
355# hash virtual methods
356#========================================================================
357
358
359sub hash_item {
360 my ($hash, $item) = @_;
361 $item = '' unless defined $item;
362 return if $PRIVATE && $item =~ /$PRIVATE/;
363 $hash->{ $item };
364}
365
366sub hash_hash {
367 $_[0];
368}
369
370sub hash_size {
371 scalar keys %{$_[0]};
372}
373
374sub hash_empty {
375 return 0 == hash_size($_[0]) ? 1 : 0;
376}
377
378sub hash_each {
379 # this will be changed in TT3 to do what hash_pairs() does
380 [ %{ $_[0] } ];
381}
382
383sub hash_keys {
384 [ keys %{ $_[0] } ];
385}
386
387sub hash_values {
388 [ values %{ $_[0] } ];
389}
390
391sub hash_items {
392 [ %{ $_[0] } ];
393}
394
395sub hash_pairs {
396 [ map {
397 { key => $_ , value => $_[0]->{ $_ } }
398 }
399 sort keys %{ $_[0] }
400 ];
401}
402
403sub hash_list {
404 my ($hash, $what) = @_;
405 $what ||= '';
406 return ($what eq 'keys') ? [ keys %$hash ]
407 : ($what eq 'values') ? [ values %$hash ]
408 : ($what eq 'each') ? [ %$hash ]
409 : # for now we do what pairs does but this will be changed
410 # in TT3 to return [ $hash ] by default
411 [ map { { key => $_ , value => $hash->{ $_ } } }
412 sort keys %$hash
413 ];
414}
415
416sub hash_exists {
417 exists $_[0]->{ $_[1] };
418}
419
420sub hash_defined {
421 # return the item requested, or 1 if no argument
422 # to indicate that the hash itself is defined
423 my $hash = shift;
424 return @_ ? defined $hash->{ $_[0] } : 1;
425}
426
427sub hash_delete {
428 my $hash = shift;
429 delete $hash->{ $_ } for @_;
430}
431
432sub hash_import {
433 my ($hash, $imp) = @_;
434 $imp = {} unless ref $imp eq 'HASH';
435 @$hash{ keys %$imp } = values %$imp;
436 return '';
437}
438
439sub hash_sort {
440 my ($hash) = @_;
441 [ sort { lc $hash->{$a} cmp lc $hash->{$b} } (keys %$hash) ];
442}
443
444sub hash_nsort {
445 my ($hash) = @_;
446 [ sort { $hash->{$a} <=> $hash->{$b} } (keys %$hash) ];
447}
448
449
450#========================================================================
451# list virtual methods
452#========================================================================
453
454
455sub list_item {
456 $_[0]->[ $_[1] || 0 ];
457}
458
459sub list_list {
460 $_[0];
461}
462
463sub list_hash {
464 my $list = shift;
465 if (@_) {
466 my $n = shift || 0;
467 return { map { ($n++, $_) } @$list };
468 }
4692142µs240µs
# spent 25µs (10+15) within Template::VMethods::BEGIN@469 which was called: # once (10µs+15µs) by Template::Stash::BEGIN@24 at line 469
no warnings;
# spent 25µs making 1 call to Template::VMethods::BEGIN@469 # spent 15µs making 1 call to warnings::unimport
470 return { @$list };
471}
472
473sub list_push {
474 my $list = shift;
475 push(@$list, @_);
476 return '';
477}
478
479sub list_pop {
480 my $list = shift;
481 pop(@$list);
482}
483
484sub list_unshift {
485 my $list = shift;
486 unshift(@$list, @_);
487 return '';
488}
489
490sub list_shift {
491 my $list = shift;
492 shift(@$list);
493}
494
495sub list_max {
496240µs228µs
# spent 17µs (6+11) within Template::VMethods::BEGIN@496 which was called: # once (6µs+11µs) by Template::Stash::BEGIN@24 at line 496
no warnings;
# spent 17µs making 1 call to Template::VMethods::BEGIN@496 # spent 11µs making 1 call to warnings::unimport
497 my $list = shift;
498 $#$list;
499}
500
501sub list_size {
5022926µs225µs
# spent 15µs (6+10) within Template::VMethods::BEGIN@502 which was called: # once (6µs+10µs) by Template::Stash::BEGIN@24 at line 502
no warnings;
# spent 15µs making 1 call to Template::VMethods::BEGIN@502 # spent 10µs making 1 call to warnings::unimport
503 my $list = shift;
504 $#$list + 1;
505}
506
507sub list_empty {
508 return 0 == list_size($_[0]) ? 1 : 0;
509}
510
511sub list_defined {
512 # return the item requested, or 1 if no argument to
513 # indicate that the hash itself is defined
514 my $list = shift;
515 return 1 unless @_; # list.defined is always true
516 return unless looks_like_number $_[0]; # list.defined('bah') is always false
517 return defined $list->[$_[0]]; # list.defined(n)
518}
519
520sub list_first {
521 my $list = shift;
522 return $list->[0] unless @_;
523 return [ @$list[0..$_[0]-1] ];
524}
525
526sub list_last {
527 my $list = shift;
528 return $list->[-1] unless @_;
529 return [ @$list[-$_[0]..-1] ];
530}
531
532sub list_reverse {
533 my $list = shift;
534 [ reverse @$list ];
535}
536
537sub list_grep {
538 my ($list, $pattern) = @_;
539 $pattern ||= '';
540 return [ grep /$pattern/, @$list ];
541}
542
543sub list_join {
544 my ($list, $joint) = @_;
545 join(defined $joint ? $joint : ' ',
546 map { defined $_ ? $_ : '' } @$list);
547}
548
549sub _list_sort_make_key {
550 my ($item, $fields) = @_;
551 my @keys;
552
553 if (ref($item) eq 'HASH') {
554 @keys = map { $item->{ $_ } } @$fields;
555 }
556 elsif (blessed $item) {
557 @keys = map { $item->can($_) ? $item->$_() : $item } @$fields;
558 }
559 else {
560 @keys = $item;
561 }
562
563 # ugly hack to generate a single string using a delimiter that is
564 # unlikely (but not impossible) to be found in the wild.
565 return lc join('/*^UNLIKELY^*/', map { defined $_ ? $_ : '' } @keys);
566}
567
568
# spent 77.9ms (57.2+20.7) within Template::VMethods::list_sort which was called 1991 times, avg 39µs/call: # 1991 times (57.2ms+20.7ms) by Template::Stash::XS::get at line 11 of /root/tor-browser-build/input text, avg 39µs/call
sub list_sort {
56919911.76ms my ($list, @fields) = @_;
57019912.62ms return $list unless @$list > 1; # no need to sort 1 item lists
571 return [
572 @fields # Schwartzian Transform
573 ? map { $_->[0] } # for case insensitivity
574 sort { $a->[1] cmp $b->[1] }
575 map { [ $_, _list_sort_make_key($_, \@fields) ] }
576 @$list
577 : map { $_->[0] }
578 sort { $a->[1] cmp $b->[1] }
579199174.1ms199120.7ms map { [ $_, lc $_ ] }
# spent 20.7ms making 1991 calls to Template::VMethods::CORE:sort, avg 10µs/call
580 @$list,
581 ];
582}
583
584sub list_nsort {
585 my ($list, @fields) = @_;
586 return $list unless @$list > 1; # no need to sort 1 item lists
587
588 my $sort = sub {
589 my $cmp;
590
591 if(@fields) {
592 # compare each field individually
593 for my $field (@fields) {
594 my $A = _list_sort_make_key($a, [ $field ]);
595 my $B = _list_sort_make_key($b, [ $field ]);
596 ($cmp = $A <=> $B) and last;
597 }
598 }
599 else {
600 my $A = _list_sort_make_key($a);
601 my $B = _list_sort_make_key($b);
602 $cmp = $A <=> $B;
603 }
604
605 $cmp;
606 };
607
608 return [ sort $sort @{ $list } ];
609}
610
611sub list_unique {
612 my %u;
613 [ grep { ++$u{$_} == 1 } @{$_[0]} ];
614}
615
616
# spent 24.1ms within Template::VMethods::list_import which was called 1991 times, avg 12µs/call: # 1991 times (24.1ms+0s) by Template::Stash::XS::get at line 11 of /root/tor-browser-build/input text, avg 12µs/call
sub list_import {
6171991949µs my $list = shift;
618199115.8ms push(@$list, grep defined, map ref eq 'ARRAY' ? @$_ : undef, @_);
61919917.12ms return $list;
620}
621
622sub list_merge {
623 my $list = shift;
624 return [ @$list, grep defined, map ref eq 'ARRAY' ? @$_ : undef, @_ ];
625}
626
627sub list_slice {
628 my ($list, $from, $to) = @_;
629 $from ||= 0;
630 $to = $#$list unless defined $to;
631 $from += @$list if $from < 0;
632 $to += @$list if $to < 0;
633 return [ @$list[$from..$to] ];
634}
635
636sub list_splice {
637 my ($list, $offset, $length, @replace) = @_;
638 if (@replace) {
639 # @replace can contain a list of multiple replace items, or
640 # be a single reference to a list
641 @replace = @{ $replace[0] }
642 if @replace == 1 && ref $replace[0] eq 'ARRAY';
643 return [ splice @$list, $offset, $length, @replace ];
644 }
645 elsif (defined $length) {
646 return [ splice @$list, $offset, $length ];
647 }
648 elsif (defined $offset) {
649 return [ splice @$list, $offset ];
650 }
651 else {
652 return [ splice(@$list) ];
653 }
654}
655
656125µs1;
657
658__END__
 
# spent 20.7ms within Template::VMethods::CORE:sort which was called 1991 times, avg 10µs/call: # 1991 times (20.7ms+0s) by Template::VMethods::list_sort at line 579, avg 10µs/call
sub Template::VMethods::CORE:sort; # opcode
# spent 600ns within Template::VMethods::__ANON__ which was called: # once (600ns+0s) by Template::VMethods::BEGIN@27 at line 27
sub Template::VMethods::__ANON__; # xsub