Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/Test/Deep/Cache/Simple.pm |
Statements | Executed 15 statements in 373µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 14µs | 16µs | BEGIN@1 | Test::Deep::Cache::
1 | 1 | 1 | 9µs | 33µs | BEGIN@7 | Test::Deep::Cache::Simple::
1 | 1 | 1 | 8µs | 28µs | BEGIN@5 | Test::Deep::Cache::Simple::
1 | 1 | 1 | 7µs | 26µs | BEGIN@10 | Test::Deep::Cache::Simple::
1 | 1 | 1 | 6µs | 14µs | BEGIN@2 | Test::Deep::Cache::
0 | 0 | 0 | 0s | 0s | __ANON__[:15] | Test::Deep::Cache::Simple::
0 | 0 | 0 | 0s | 0s | absorb | Test::Deep::Cache::Simple::
0 | 0 | 0 | 0s | 0s | add | Test::Deep::Cache::Simple::
0 | 0 | 0 | 0s | 0s | cmp | Test::Deep::Cache::Simple::
0 | 0 | 0 | 0s | 0s | fn_get_key | Test::Deep::Cache::Simple::
0 | 0 | 0 | 0s | 0s | new | Test::Deep::Cache::Simple::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | 3 | 18µs | 2 | 18µs | # spent 16µs (14+2) within Test::Deep::Cache::BEGIN@1 which was called:
# once (14µs+2µs) by Test::Deep::Cache::BEGIN@6 at line 1 # spent 16µs making 1 call to Test::Deep::Cache::BEGIN@1
# spent 2µs making 1 call to strict::import |
2 | 3 | 30µs | 2 | 21µs | # spent 14µs (6+7) within Test::Deep::Cache::BEGIN@2 which was called:
# once (6µs+7µs) by Test::Deep::Cache::BEGIN@6 at line 2 # spent 14µs making 1 call to Test::Deep::Cache::BEGIN@2
# spent 7µs making 1 call to warnings::import |
3 | |||||
4 | package Test::Deep::Cache::Simple; | ||||
5 | 3 | 19µs | 2 | 48µs | # spent 28µs (8+20) within Test::Deep::Cache::Simple::BEGIN@5 which was called:
# once (8µs+20µs) by Test::Deep::Cache::BEGIN@6 at line 5 # spent 28µs making 1 call to Test::Deep::Cache::Simple::BEGIN@5
# spent 20µs making 1 call to Exporter::import |
6 | |||||
7 | 3 | 85µs | 2 | 58µs | # spent 33µs (9+24) within Test::Deep::Cache::Simple::BEGIN@7 which was called:
# once (9µs+24µs) by Test::Deep::Cache::BEGIN@6 at line 7 # spent 33µs making 1 call to Test::Deep::Cache::Simple::BEGIN@7
# spent 24µs making 1 call to Exporter::import |
8 | |||||
9 | BEGIN | ||||
10 | # spent 26µs (7+19) within Test::Deep::Cache::Simple::BEGIN@10 which was called:
# once (7µs+19µs) by Test::Deep::Cache::BEGIN@6 at line 21 | ||||
11 | 1 | 3µs | if (grep /^weaken$/, @Scalar::Util::EXPORT_FAIL) | ||
12 | { | ||||
13 | # we're running on a version of perl that has no weak refs, so we | ||||
14 | # just install a no-op sub for weaken instead of importing it | ||||
15 | *weaken = sub {}; | ||||
16 | } | ||||
17 | else | ||||
18 | { | ||||
19 | 1 | 1µs | 1 | 19µs | Scalar::Util->import('weaken'); # spent 19µs making 1 call to Exporter::import |
20 | } | ||||
21 | 1 | 214µs | 1 | 26µs | } # spent 26µs making 1 call to Test::Deep::Cache::Simple::BEGIN@10 |
22 | |||||
23 | sub new | ||||
24 | { | ||||
25 | my $pkg = shift; | ||||
26 | |||||
27 | my $self = bless {}, $pkg; | ||||
28 | |||||
29 | return $self; | ||||
30 | } | ||||
31 | |||||
32 | sub add | ||||
33 | { | ||||
34 | my $self = shift; | ||||
35 | |||||
36 | my ($d1, $d2) = @_; | ||||
37 | { | ||||
38 | local $SIG{__DIE__}; | ||||
39 | |||||
40 | # cannot weaken read only refs, no harm if we can't as they never | ||||
41 | # disappear | ||||
42 | eval{weaken($d1)}; | ||||
43 | eval{weaken($d2)}; | ||||
44 | } | ||||
45 | |||||
46 | $self->{fn_get_key(@_)} = [$d1, $d2]; | ||||
47 | } | ||||
48 | |||||
49 | sub cmp | ||||
50 | { | ||||
51 | my $self = shift; | ||||
52 | |||||
53 | my $key = fn_get_key(@_); | ||||
54 | my $pair = $self->{$key}; | ||||
55 | |||||
56 | # are both weakened refs still valid, if not delete this entry | ||||
57 | if (ref($pair->[0]) and ref($pair->[1])) | ||||
58 | { | ||||
59 | return 1; | ||||
60 | } | ||||
61 | else | ||||
62 | { | ||||
63 | delete $self->{$key}; | ||||
64 | return 0; | ||||
65 | } | ||||
66 | } | ||||
67 | |||||
68 | sub absorb | ||||
69 | { | ||||
70 | my $self = shift; | ||||
71 | |||||
72 | my $other = shift; | ||||
73 | |||||
74 | @{$self}{keys %$other} = values %$other; | ||||
75 | } | ||||
76 | |||||
77 | sub fn_get_key | ||||
78 | { | ||||
79 | return join(",", sort (map {refaddr($_)} @_)); | ||||
80 | } | ||||
81 | 1 | 2µs | 1; |