Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/5.18.2/Text/Tabs.pm |
Statements | Executed 15 statements in 481µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 12µs | 57µs | BEGIN@9 | Text::Tabs::
1 | 1 | 1 | 9µs | 9µs | BEGIN@15 | Text::Tabs::
1 | 1 | 1 | 6µs | 17µs | BEGIN@13 | Text::Tabs::
1 | 1 | 1 | 3µs | 3µs | BEGIN@17 | Text::Tabs::
1 | 1 | 1 | 2µs | 2µs | CORE:qr (opcode) | Text::Tabs::
0 | 0 | 0 | 0s | 0s | _xlen | Text::Tabs::
0 | 0 | 0 | 0s | 0s | _xpos | Text::Tabs::
0 | 0 | 0 | 0s | 0s | expand | Text::Tabs::
0 | 0 | 0 | 0s | 0s | unexpand | Text::Tabs::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | package Text::Tabs; | ||||
3 | |||||
4 | 1 | 800ns | require Exporter; | ||
5 | |||||
6 | 1 | 6µs | @ISA = (Exporter); | ||
7 | 1 | 800ns | @EXPORT = qw(expand unexpand $tabstop); | ||
8 | |||||
9 | 2 | 29µs | 2 | 102µs | # spent 57µs (12+45) within Text::Tabs::BEGIN@9 which was called:
# once (12µs+45µs) by Text::Wrap::BEGIN@35 at line 9 # spent 57µs making 1 call to Text::Tabs::BEGIN@9
# spent 45µs making 1 call to vars::import |
10 | 1 | 200ns | $VERSION = 2012.0818; | ||
11 | 1 | 100ns | $SUBVERSION = 'modern'; | ||
12 | |||||
13 | 2 | 19µs | 2 | 27µs | # spent 17µs (6+10) within Text::Tabs::BEGIN@13 which was called:
# once (6µs+10µs) by Text::Wrap::BEGIN@35 at line 13 # spent 17µs making 1 call to Text::Tabs::BEGIN@13
# spent 10µs making 1 call to strict::import |
14 | |||||
15 | 2 | 40µs | 1 | 9µs | # spent 9µs within Text::Tabs::BEGIN@15 which was called:
# once (9µs+0s) by Text::Wrap::BEGIN@35 at line 15 # spent 9µs making 1 call to Text::Tabs::BEGIN@15 |
16 | |||||
17 | # spent 3µs within Text::Tabs::BEGIN@17 which was called:
# once (3µs+0s) by Text::Wrap::BEGIN@35 at line 20 | ||||
18 | 1 | 200ns | $tabstop = 8; | ||
19 | 1 | 3µs | $debug = 0; | ||
20 | 1 | 370µs | 1 | 3µs | } # spent 3µs making 1 call to Text::Tabs::BEGIN@17 |
21 | |||||
22 | 1 | 9µs | 1 | 2µs | my $CHUNK = qr/\X/; # spent 2µs making 1 call to Text::Tabs::CORE:qr |
23 | |||||
24 | sub _xlen (_) { scalar(() = $_[0] =~ /$CHUNK/g) } | ||||
25 | sub _xpos (_) { _xlen( substr( $_[0], 0, pos($_[0]) ) ) } | ||||
26 | |||||
27 | sub expand { | ||||
28 | my @l; | ||||
29 | my $pad; | ||||
30 | for ( @_ ) { | ||||
31 | my $s = ''; | ||||
32 | for (split(/^/m, $_, -1)) { | ||||
33 | my $offs = 0; | ||||
34 | s{\t}{ | ||||
35 | # this works on both 5.10 and 5.11 | ||||
36 | $pad = $tabstop - (_xlen(${^PREMATCH}) + $offs) % $tabstop; | ||||
37 | # this works on 5.11, but fails on 5.10 | ||||
38 | #XXX# $pad = $tabstop - (_xpos() + $offs) % $tabstop; | ||||
39 | $offs += $pad - 1; | ||||
40 | " " x $pad; | ||||
41 | }peg; | ||||
42 | $s .= $_; | ||||
43 | } | ||||
44 | push(@l, $s); | ||||
45 | } | ||||
46 | return @l if wantarray; | ||||
47 | return $l[0]; | ||||
48 | } | ||||
49 | |||||
50 | sub unexpand | ||||
51 | { | ||||
52 | my (@l) = @_; | ||||
53 | my @e; | ||||
54 | my $x; | ||||
55 | my $line; | ||||
56 | my @lines; | ||||
57 | my $lastbit; | ||||
58 | my $ts_as_space = " " x $tabstop; | ||||
59 | for $x (@l) { | ||||
60 | @lines = split("\n", $x, -1); | ||||
61 | for $line (@lines) { | ||||
62 | $line = expand($line); | ||||
63 | @e = split(/(${CHUNK}{$tabstop})/,$line,-1); | ||||
64 | $lastbit = pop(@e); | ||||
65 | $lastbit = '' | ||||
66 | unless defined $lastbit; | ||||
67 | $lastbit = "\t" | ||||
68 | if $lastbit eq $ts_as_space; | ||||
69 | for $_ (@e) { | ||||
70 | if ($debug) { | ||||
71 | my $x = $_; | ||||
72 | $x =~ s/\t/^I\t/gs; | ||||
73 | print "sub on '$x'\n"; | ||||
74 | } | ||||
75 | s/ +$/\t/; | ||||
76 | } | ||||
77 | $line = join('',@e, $lastbit); | ||||
78 | } | ||||
79 | $x = join("\n", @lines); | ||||
80 | } | ||||
81 | return @l if wantarray; | ||||
82 | return $l[0]; | ||||
83 | } | ||||
84 | |||||
85 | 1 | 4µs | 1; | ||
86 | __END__ | ||||
# spent 2µs within Text::Tabs::CORE:qr which was called:
# once (2µs+0s) by Text::Wrap::BEGIN@35 at line 22 |