Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/5.18.2/Tie/Array.pm |
Statements | Executed 11 statements in 1.11ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 26µs | 26µs | BEGIN@3 | Tie::Array::
1 | 1 | 1 | 12µs | 62µs | BEGIN@5 | Tie::Array::
1 | 1 | 1 | 12µs | 49µs | BEGIN@86 | Tie::StdArray::
1 | 1 | 1 | 10µs | 30µs | BEGIN@4 | Tie::Array::
0 | 0 | 0 | 0s | 0s | CLEAR | Tie::Array::
0 | 0 | 0 | 0s | 0s | DELETE | Tie::Array::
0 | 0 | 0 | 0s | 0s | DESTROY | Tie::Array::
0 | 0 | 0 | 0s | 0s | EXISTS | Tie::Array::
0 | 0 | 0 | 0s | 0s | EXTEND | Tie::Array::
0 | 0 | 0 | 0s | 0s | POP | Tie::Array::
0 | 0 | 0 | 0s | 0s | PUSH | Tie::Array::
0 | 0 | 0 | 0s | 0s | SHIFT | Tie::Array::
0 | 0 | 0 | 0s | 0s | SPLICE | Tie::Array::
0 | 0 | 0 | 0s | 0s | UNSHIFT | Tie::Array::
0 | 0 | 0 | 0s | 0s | CLEAR | Tie::StdArray::
0 | 0 | 0 | 0s | 0s | DELETE | Tie::StdArray::
0 | 0 | 0 | 0s | 0s | EXISTS | Tie::StdArray::
0 | 0 | 0 | 0s | 0s | FETCH | Tie::StdArray::
0 | 0 | 0 | 0s | 0s | FETCHSIZE | Tie::StdArray::
0 | 0 | 0 | 0s | 0s | POP | Tie::StdArray::
0 | 0 | 0 | 0s | 0s | PUSH | Tie::StdArray::
0 | 0 | 0 | 0s | 0s | SHIFT | Tie::StdArray::
0 | 0 | 0 | 0s | 0s | SPLICE | Tie::StdArray::
0 | 0 | 0 | 0s | 0s | STORE | Tie::StdArray::
0 | 0 | 0 | 0s | 0s | STORESIZE | Tie::StdArray::
0 | 0 | 0 | 0s | 0s | TIEARRAY | Tie::StdArray::
0 | 0 | 0 | 0s | 0s | UNSHIFT | Tie::StdArray::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Tie::Array; | ||||
2 | |||||
3 | 2 | 62µs | 1 | 26µs | # spent 26µs within Tie::Array::BEGIN@3 which was called:
# once (26µs+0s) by Env::Array::BEGIN@123 at line 3 # spent 26µs making 1 call to Tie::Array::BEGIN@3 |
4 | 2 | 30µs | 2 | 50µs | # spent 30µs (10+20) within Tie::Array::BEGIN@4 which was called:
# once (10µs+20µs) by Env::Array::BEGIN@123 at line 4 # spent 30µs making 1 call to Tie::Array::BEGIN@4
# spent 20µs making 1 call to strict::import |
5 | 2 | 608µs | 2 | 112µs | # spent 62µs (12+50) within Tie::Array::BEGIN@5 which was called:
# once (12µs+50µs) by Env::Array::BEGIN@123 at line 5 # spent 62µs making 1 call to Tie::Array::BEGIN@5
# spent 50µs making 1 call to Exporter::import |
6 | 1 | 1µs | our $VERSION = '1.05'; | ||
7 | |||||
8 | # Pod documentation after __END__ below. | ||||
9 | |||||
10 | sub DESTROY { } | ||||
11 | sub EXTEND { } | ||||
12 | sub UNSHIFT { scalar shift->SPLICE(0,0,@_) } | ||||
13 | sub SHIFT { shift->SPLICE(0,1) } | ||||
14 | sub CLEAR { shift->STORESIZE(0) } | ||||
15 | |||||
16 | sub PUSH | ||||
17 | { | ||||
18 | my $obj = shift; | ||||
19 | my $i = $obj->FETCHSIZE; | ||||
20 | $obj->STORE($i++, shift) while (@_); | ||||
21 | } | ||||
22 | |||||
23 | sub POP | ||||
24 | { | ||||
25 | my $obj = shift; | ||||
26 | my $newsize = $obj->FETCHSIZE - 1; | ||||
27 | my $val; | ||||
28 | if ($newsize >= 0) | ||||
29 | { | ||||
30 | $val = $obj->FETCH($newsize); | ||||
31 | $obj->STORESIZE($newsize); | ||||
32 | } | ||||
33 | $val; | ||||
34 | } | ||||
35 | |||||
36 | sub SPLICE { | ||||
37 | my $obj = shift; | ||||
38 | my $sz = $obj->FETCHSIZE; | ||||
39 | my $off = (@_) ? shift : 0; | ||||
40 | $off += $sz if ($off < 0); | ||||
41 | my $len = (@_) ? shift : $sz - $off; | ||||
42 | $len += $sz - $off if $len < 0; | ||||
43 | my @result; | ||||
44 | for (my $i = 0; $i < $len; $i++) { | ||||
45 | push(@result,$obj->FETCH($off+$i)); | ||||
46 | } | ||||
47 | $off = $sz if $off > $sz; | ||||
48 | $len -= $off + $len - $sz if $off + $len > $sz; | ||||
49 | if (@_ > $len) { | ||||
50 | # Move items up to make room | ||||
51 | my $d = @_ - $len; | ||||
52 | my $e = $off+$len; | ||||
53 | $obj->EXTEND($sz+$d); | ||||
54 | for (my $i=$sz-1; $i >= $e; $i--) { | ||||
55 | my $val = $obj->FETCH($i); | ||||
56 | $obj->STORE($i+$d,$val); | ||||
57 | } | ||||
58 | } | ||||
59 | elsif (@_ < $len) { | ||||
60 | # Move items down to close the gap | ||||
61 | my $d = $len - @_; | ||||
62 | my $e = $off+$len; | ||||
63 | for (my $i=$off+$len; $i < $sz; $i++) { | ||||
64 | my $val = $obj->FETCH($i); | ||||
65 | $obj->STORE($i-$d,$val); | ||||
66 | } | ||||
67 | $obj->STORESIZE($sz-$d); | ||||
68 | } | ||||
69 | for (my $i=0; $i < @_; $i++) { | ||||
70 | $obj->STORE($off+$i,$_[$i]); | ||||
71 | } | ||||
72 | return wantarray ? @result : pop @result; | ||||
73 | } | ||||
74 | |||||
75 | sub EXISTS { | ||||
76 | my $pkg = ref $_[0]; | ||||
77 | croak "$pkg doesn't define an EXISTS method"; | ||||
78 | } | ||||
79 | |||||
80 | sub DELETE { | ||||
81 | my $pkg = ref $_[0]; | ||||
82 | croak "$pkg doesn't define a DELETE method"; | ||||
83 | } | ||||
84 | |||||
85 | package Tie::StdArray; | ||||
86 | 2 | 397µs | 2 | 85µs | # spent 49µs (12+37) within Tie::StdArray::BEGIN@86 which was called:
# once (12µs+37µs) by Env::Array::BEGIN@123 at line 86 # spent 49µs making 1 call to Tie::StdArray::BEGIN@86
# spent 37µs making 1 call to vars::import |
87 | 1 | 9µs | @ISA = 'Tie::Array'; | ||
88 | |||||
89 | sub TIEARRAY { bless [], $_[0] } | ||||
90 | sub FETCHSIZE { scalar @{$_[0]} } | ||||
91 | sub STORESIZE { $#{$_[0]} = $_[1]-1 } | ||||
92 | sub STORE { $_[0]->[$_[1]] = $_[2] } | ||||
93 | sub FETCH { $_[0]->[$_[1]] } | ||||
94 | sub CLEAR { @{$_[0]} = () } | ||||
95 | sub POP { pop(@{$_[0]}) } | ||||
96 | sub PUSH { my $o = shift; push(@$o,@_) } | ||||
97 | sub SHIFT { shift(@{$_[0]}) } | ||||
98 | sub UNSHIFT { my $o = shift; unshift(@$o,@_) } | ||||
99 | sub EXISTS { exists $_[0]->[$_[1]] } | ||||
100 | sub DELETE { delete $_[0]->[$_[1]] } | ||||
101 | |||||
102 | sub SPLICE | ||||
103 | { | ||||
104 | my $ob = shift; | ||||
105 | my $sz = $ob->FETCHSIZE; | ||||
106 | my $off = @_ ? shift : 0; | ||||
107 | $off += $sz if $off < 0; | ||||
108 | my $len = @_ ? shift : $sz-$off; | ||||
109 | return splice(@$ob,$off,$len,@_); | ||||
110 | } | ||||
111 | |||||
112 | 1 | 5µs | 1; | ||
113 | |||||
114 | __END__ |