Filename | /home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Text/Unidecode.pm |
Statements | Executed 27 statements in 827µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 197µs | 202µs | BEGIN@6 | Text::Unidecode::
1 | 1 | 1 | 26µs | 32µs | BEGIN@4 | Text::Unidecode::
1 | 1 | 1 | 22µs | 24µs | unidecode | Text::Unidecode::
1 | 1 | 1 | 12µs | 129µs | BEGIN@7 | Text::Unidecode::
1 | 1 | 1 | 11µs | 19µs | BEGIN@5 | Text::Unidecode::
1 | 1 | 1 | 7µs | 7µs | BEGIN@13 | Text::Unidecode::
1 | 1 | 1 | 2µs | 2µs | CORE:subst (opcode) | Text::Unidecode::
0 | 0 | 0 | 0s | 0s | t | Text::Unidecode::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | 1 | 51µs | require 5.006; | ||
3 | package Text::Unidecode; # Time-stamp: "2001-07-14 02:29:41 MDT" | ||||
4 | 2 | 28µs | 2 | 38µs | # spent 32µs (26+6) within Text::Unidecode::BEGIN@4 which was called:
# once (26µs+6µs) by Hailo::Tokenizer::Words::BEGIN@8 at line 4 # spent 32µs making 1 call to Text::Unidecode::BEGIN@4
# spent 6µs making 1 call to utf8::import |
5 | 2 | 25µs | 2 | 28µs | # spent 19µs (11+8) within Text::Unidecode::BEGIN@5 which was called:
# once (11µs+8µs) by Hailo::Tokenizer::Words::BEGIN@8 at line 5 # spent 19µs making 1 call to Text::Unidecode::BEGIN@5
# spent 8µs making 1 call to strict::import |
6 | 2 | 211µs | 2 | 205µs | # spent 202µs (197+4) within Text::Unidecode::BEGIN@6 which was called:
# once (197µs+4µs) by Hailo::Tokenizer::Words::BEGIN@8 at line 6 # spent 202µs making 1 call to Text::Unidecode::BEGIN@6
# spent 4µs making 1 call to integer::import |
7 | 2 | 66µs | 2 | 246µs | # spent 129µs (12+117) within Text::Unidecode::BEGIN@7 which was called:
# once (12µs+117µs) by Hailo::Tokenizer::Words::BEGIN@8 at line 7 # spent 129µs making 1 call to Text::Unidecode::BEGIN@7
# spent 117µs making 1 call to vars::import |
8 | 1 | 2µs | $VERSION = '0.04'; | ||
9 | 1 | 1µs | require Exporter; | ||
10 | 1 | 6µs | @ISA = ('Exporter'); | ||
11 | 1 | 1µs | @EXPORT = ('unidecode'); | ||
12 | |||||
13 | 1 | 349µs | 1 | 7µs | # spent 7µs within Text::Unidecode::BEGIN@13 which was called:
# once (7µs+0s) by Hailo::Tokenizer::Words::BEGIN@8 at line 13 # spent 7µs making 1 call to Text::Unidecode::BEGIN@13 |
14 | |||||
15 | 1 | 44µs | $NULLMAP = [('[?] ') x 0x100]; # for blocks we can't load | ||
16 | |||||
17 | #-------------------------------------------------------------------------- | ||||
18 | { | ||||
19 | 3 | 9µs | my $x = join '', "\x00" .. "\x7F"; | ||
20 | 1 | 24µs | die "the 7-bit purity test fails!" unless $x eq unidecode($x); # spent 24µs making 1 call to Text::Unidecode::unidecode | ||
21 | } | ||||
22 | |||||
23 | #-------------------------------------------------------------------------- | ||||
24 | |||||
25 | # spent 24µs (22+2) within Text::Unidecode::unidecode which was called:
# once (22µs+2µs) by Hailo::Tokenizer::Words::BEGIN@8 at line 20 | ||||
26 | # Destructive in void context -- in other contexts, nondestructive. | ||||
27 | |||||
28 | 6 | 14µs | unless(@_) { | ||
29 | # Nothing coming in | ||||
30 | return() if wantarray; | ||||
31 | return ''; | ||||
32 | } | ||||
33 | @_ = map $_, @_ if defined wantarray; | ||||
34 | # We're in list or scalar context, NOT void context. | ||||
35 | # So make @_'s items no longer be aliases. | ||||
36 | # Otherwise, let @_ be aliases, and alter in-place. | ||||
37 | |||||
38 | foreach my $x (@_) { | ||||
39 | 2 | 12µs | next unless defined $x; | ||
40 | 1 | 2µs | $x =~ s~([^\x00-\x7f])~${$Char[ord($1)>>8]||t($1)}[ord($1)&255]~egs; # spent 2µs making 1 call to Text::Unidecode::CORE:subst | ||
41 | # Replace character 0xABCD with $Char[0xAB][0xCD], loading | ||||
42 | # the table as needed. | ||||
43 | } | ||||
44 | |||||
45 | return unless defined wantarray; # void context | ||||
46 | return @_ if wantarray; # normal list context -- return the copies | ||||
47 | # Else normal scalar context: | ||||
48 | return $_[0] if @_ == 1; | ||||
49 | return join '', @_; # rarer fallthru: a list in, but a scalar out. | ||||
50 | } | ||||
51 | |||||
52 | sub t { | ||||
53 | # load (and return) a char table for this character | ||||
54 | # this should get called only once per table per session. | ||||
55 | my $bank = ord($_[0]) >> 8; | ||||
56 | return $Char[$bank] if $Char[$bank]; | ||||
57 | |||||
58 | { | ||||
59 | DEBUG and printf "Loading %s::x%02x\n", __PACKAGE__, $bank; | ||||
60 | local $SIG{'__DIE__'}; | ||||
61 | eval(sprintf 'require %s::x%02x;', __PACKAGE__, $bank); | ||||
62 | } | ||||
63 | |||||
64 | # Now see how that fared... | ||||
65 | if(ref($Char[$bank] || '') ne 'ARRAY') { | ||||
66 | DEBUG > 1 and print | ||||
67 | " Loading failed for bank $bank (err $@). Using null map.\n"; | ||||
68 | return $Char[$bank] = $NULLMAP; | ||||
69 | } else { | ||||
70 | DEBUG > 1 and print " Succeeded.\n"; | ||||
71 | if(DEBUG) { | ||||
72 | # Sanity-check it: | ||||
73 | my $cb = $Char[$bank]; | ||||
74 | unless(@$cb == 256) { | ||||
75 | printf "Block x%02x is of size %d -- chopping to 256\n", | ||||
76 | scalar(@$cb); | ||||
77 | $#$cb = 255; # pre-extend the array, or chop it to size. | ||||
78 | } | ||||
79 | for(my $i = 0; $i < 256; ++$i) { | ||||
80 | unless(defined $cb->[$i]) { | ||||
81 | printf "Undef at position %d in block x%02x\n", | ||||
82 | $i, $bank; | ||||
83 | $cb->[$i] = ''; | ||||
84 | } | ||||
85 | } | ||||
86 | } | ||||
87 | return $Char[$bank]; | ||||
88 | } | ||||
89 | } | ||||
90 | |||||
91 | #-------------------------------------------------------------------------- | ||||
92 | 1 | 7µs | 1; | ||
93 | __END__ | ||||
# spent 2µs within Text::Unidecode::CORE:subst which was called:
# once (2µs+0s) by Text::Unidecode::unidecode at line 40 |