Filename | /Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/String/RewritePrefix.pm |
Statements | Executed 50 statements in 425µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2 | 1 | 1 | 21µs | 25µs | _new_rewriter | String::RewritePrefix::
2 | 1 | 1 | 16µs | 16µs | __ANON__[:57] | String::RewritePrefix::
2 | 1 | 1 | 14µs | 55µs | rewrite | String::RewritePrefix::
1 | 1 | 1 | 12µs | 253µs | BEGIN@11 | String::RewritePrefix::
1 | 1 | 1 | 10µs | 20µs | BEGIN@1 | MooseX::Storage::
1 | 1 | 1 | 6µs | 9µs | BEGIN@2 | MooseX::Storage::
2 | 1 | 1 | 4µs | 4µs | CORE:sort (opcode) | String::RewritePrefix::
1 | 1 | 1 | 3µs | 3µs | BEGIN@4 | String::RewritePrefix::
1 | 1 | 1 | 3µs | 3µs | BEGIN@7 | String::RewritePrefix::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | 2 | 23µs | 2 | 31µs | # spent 20µs (10+11) within MooseX::Storage::BEGIN@1 which was called:
# once (10µs+11µs) by MooseX::Storage::BEGIN@13 at line 1 # spent 20µs making 1 call to MooseX::Storage::BEGIN@1
# spent 10µs making 1 call to strict::import |
2 | 2 | 34µs | 2 | 12µs | # spent 9µs (6+3) within MooseX::Storage::BEGIN@2 which was called:
# once (6µs+3µs) by MooseX::Storage::BEGIN@13 at line 2 # spent 9µs making 1 call to MooseX::Storage::BEGIN@2
# spent 3µs making 1 call to warnings::import |
3 | package String::RewritePrefix; | ||||
4 | # spent 3µs within String::RewritePrefix::BEGIN@4 which was called:
# once (3µs+0s) by MooseX::Storage::BEGIN@13 at line 6 | ||||
5 | 1 | 4µs | $String::RewritePrefix::VERSION = '0.006'; | ||
6 | 1 | 14µs | 1 | 3µs | } # spent 3µs making 1 call to String::RewritePrefix::BEGIN@4 |
7 | 2 | 32µs | 1 | 3µs | # spent 3µs within String::RewritePrefix::BEGIN@7 which was called:
# once (3µs+0s) by MooseX::Storage::BEGIN@13 at line 7 # spent 3µs making 1 call to String::RewritePrefix::BEGIN@7 |
8 | # ABSTRACT: rewrite strings based on a set of known prefixes | ||||
9 | |||||
10 | # 0.972 allows \'method_name' form -- rjbs, 2010-10-25 | ||||
11 | 1 | 200ns | # spent 253µs (12+241) within String::RewritePrefix::BEGIN@11 which was called:
# once (12µs+241µs) by MooseX::Storage::BEGIN@13 at line 13 | ||
12 | exports => [ rewrite => \'_new_rewriter' ], | ||||
13 | 2 | 266µs | 3 | 494µs | }; # spent 253µs making 1 call to String::RewritePrefix::BEGIN@11
# spent 233µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337]
# spent 8µs making 1 call to UNIVERSAL::VERSION |
14 | |||||
15 | |||||
16 | # spent 55µs (14+42) within String::RewritePrefix::rewrite which was called 2 times, avg 28µs/call:
# 2 times (14µs+42µs) by MooseX::Storage::_rewrite_role_name at line 31 of MooseX/Storage.pm, avg 28µs/call | ||||
17 | 2 | 1µs | my ($self, $arg, @rest) = @_; | ||
18 | 2 | 8µs | 4 | 42µs | return $self->_new_rewriter(rewrite => { prefixes => $arg })->(@rest); # spent 25µs making 2 calls to String::RewritePrefix::_new_rewriter, avg 13µs/call
# spent 16µs making 2 calls to String::RewritePrefix::__ANON__[String/RewritePrefix.pm:57], avg 8µs/call |
19 | } | ||||
20 | |||||
21 | # spent 25µs (21+4) within String::RewritePrefix::_new_rewriter which was called 2 times, avg 13µs/call:
# 2 times (21µs+4µs) by String::RewritePrefix::rewrite at line 18, avg 13µs/call | ||||
22 | 2 | 700ns | my ($self, $name, $arg) = @_; | ||
23 | 2 | 700ns | my $rewrites = $arg->{prefixes} || {}; | ||
24 | |||||
25 | 2 | 100ns | my @rewrites; | ||
26 | 2 | 12µs | 2 | 4µs | for my $prefix (sort { length $b <=> length $a } keys %$rewrites) { # spent 4µs making 2 calls to String::RewritePrefix::CORE:sort, avg 2µs/call |
27 | 4 | 3µs | push @rewrites, ($prefix, $rewrites->{$prefix}); | ||
28 | } | ||||
29 | |||||
30 | # spent 16µs within String::RewritePrefix::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/String/RewritePrefix.pm:57] which was called 2 times, avg 8µs/call:
# 2 times (16µs+0s) by String::RewritePrefix::rewrite at line 18, avg 8µs/call | ||||
31 | 2 | 100ns | my @result; | ||
32 | |||||
33 | 2 | 500ns | Carp::cluck("string rewriter invoked in void context") | ||
34 | unless defined wantarray; | ||||
35 | |||||
36 | 2 | 600ns | Carp::croak("attempt to rewrite multiple strings outside of list context") | ||
37 | if @_ > 1 and ! wantarray; | ||||
38 | |||||
39 | 2 | 2µs | STRING: for my $str (@_) { | ||
40 | 2 | 1µs | for (my $i = 0; $i < @rewrites; $i += 2) { | ||
41 | 3 | 1µs | if (index($str, $rewrites[$i]) == 0) { | ||
42 | 2 | 800ns | if (ref $rewrites[$i+1]) { | ||
43 | my $rest = substr $str, length($rewrites[$i]); | ||||
44 | my $str = $rewrites[ $i+1 ]->($rest); | ||||
45 | push @result, (defined $str ? $str : '') . $rest; | ||||
46 | } else { | ||||
47 | 2 | 3µs | push @result, $rewrites[$i+1] . substr $str, length($rewrites[$i]); | ||
48 | } | ||||
49 | 2 | 1µs | next STRING; | ||
50 | } | ||||
51 | } | ||||
52 | |||||
53 | push @result, $str; | ||||
54 | } | ||||
55 | |||||
56 | 2 | 5µs | return wantarray ? @result : $result[0]; | ||
57 | 2 | 10µs | }; | ||
58 | } | ||||
59 | |||||
60 | 1 | 2µs | 1; | ||
61 | |||||
62 | __END__ | ||||
# spent 4µs within String::RewritePrefix::CORE:sort which was called 2 times, avg 2µs/call:
# 2 times (4µs+0s) by String::RewritePrefix::_new_rewriter at line 26, avg 2µs/call |