Filename | /usr/lib/x86_64-linux-gnu/perl/5.28/Encode.pm |
Statements | Executed 95096 statements in 329ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
4038 | 1 | 1 | 122ms | 252ms | encode | Encode::
5051 | 1 | 1 | 62.0ms | 74.7ms | getEncoding | Encode::
5051 | 2 | 1 | 60.1ms | 135ms | find_encoding | Encode::
1013 | 1 | 1 | 37.8ms | 79.3ms | decode | Encode::
4038 | 1 | 1 | 21.5ms | 21.5ms | encode (xsub) | Encode::utf8::
5051 | 1 | 1 | 12.7ms | 12.7ms | CORE:subst (opcode) | Encode::
1013 | 1 | 1 | 10.8ms | 14.7ms | decode (xsub) | Encode::utf8::
1 | 1 | 1 | 2.36ms | 5.18ms | BEGIN@55 | Encode::
1013 | 1 | 1 | 2.33ms | 2.33ms | is_utf8 (xsub) | Encode::
1 | 1 | 1 | 1.71ms | 2.14ms | BEGIN@52 | Encode::
1 | 1 | 1 | 539µs | 577µs | BEGIN@53 | Encode::
1 | 1 | 1 | 268µs | 1.55ms | BEGIN@305 | Encode::UTF_EBCDIC::
1 | 1 | 1 | 217µs | 219µs | BEGIN@368 | Encode::utf8::
8 | 3 | 1 | 41µs | 49µs | define_encoding | Encode::
1 | 1 | 1 | 28µs | 50µs | onBOOT (xsub) | Encode::
1 | 1 | 1 | 13µs | 223µs | BEGIN@9 | Encode::
1 | 1 | 1 | 12µs | 22µs | BEGIN@354 | Encode::utf8::
1 | 1 | 1 | 11µs | 54µs | BEGIN@15 | Encode::
1 | 1 | 1 | 10µs | 14µs | BEGIN@5 | Encode::
1 | 1 | 1 | 7µs | 64µs | BEGIN@7 | Encode::
1 | 1 | 1 | 6µs | 21µs | BEGIN@334 | Encode::Internal::
1 | 1 | 1 | 6µs | 31µs | BEGIN@6 | Encode::
1 | 1 | 1 | 6µs | 19µs | BEGIN@349 | Encode::XS::
1 | 1 | 1 | 3µs | 3µs | CORE:match (opcode) | Encode::
1 | 1 | 1 | 2µs | 2µs | define_alias | Encode::
1 | 1 | 1 | 800ns | 800ns | __ANON__ (xsub) | Encode::
0 | 0 | 0 | 0s | 0s | decode | Encode::Internal::
0 | 0 | 0 | 0s | 0s | decode | Encode::UTF_EBCDIC::
0 | 0 | 0 | 0s | 0s | encode | Encode::UTF_EBCDIC::
0 | 0 | 0 | 0s | 0s | __ANON__[:193] | Encode::
0 | 0 | 0 | 0s | 0s | __ANON__[:222] | Encode::
0 | 0 | 0 | 0s | 0s | __ANON__[:256] | Encode::
0 | 0 | 0 | 0s | 0s | __ANON__[:268] | Encode::
0 | 0 | 0 | 0s | 0s | clone_encoding | Encode::
0 | 0 | 0 | 0s | 0s | decode_utf8 | Encode::
0 | 0 | 0 | 0s | 0s | encode_utf8 | Encode::
0 | 0 | 0 | 0s | 0s | encodings | Encode::
0 | 0 | 0 | 0s | 0s | find_alias | Encode::
0 | 0 | 0 | 0s | 0s | find_mime_encoding | Encode::
0 | 0 | 0 | 0s | 0s | from_to | Encode::
0 | 0 | 0 | 0s | 0s | perlio_ok | Encode::
0 | 0 | 0 | 0s | 0s | resolve_alias | Encode::
0 | 0 | 0 | 0s | 0s | cat_decode | Encode::utf8::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # | ||||
2 | # $Id: Encode.pm,v 2.97 2018/02/21 12:14:24 dankogai Exp $ | ||||
3 | # | ||||
4 | package Encode; | ||||
5 | 2 | 21µs | 2 | 18µs | # spent 14µs (10+4) within Encode::BEGIN@5 which was called:
# once (10µs+4µs) by RBM::BEGIN@6 at line 5 # spent 14µs making 1 call to Encode::BEGIN@5
# spent 4µs making 1 call to strict::import |
6 | 2 | 29µs | 2 | 57µs | # spent 31µs (6+25) within Encode::BEGIN@6 which was called:
# once (6µs+25µs) by RBM::BEGIN@6 at line 6 # spent 31µs making 1 call to Encode::BEGIN@6
# spent 25µs making 1 call to warnings::import |
7 | 2 | 64µs | 2 | 122µs | # spent 64µs (7+58) within Encode::BEGIN@7 which was called:
# once (7µs+58µs) by RBM::BEGIN@6 at line 7 # spent 64µs making 1 call to Encode::BEGIN@7
# spent 58µs making 1 call to constant::import |
8 | our $VERSION; | ||||
9 | # spent 223µs (13+209) within Encode::BEGIN@9 which was called:
# once (13µs+209µs) by RBM::BEGIN@6 at line 13 | ||||
10 | 1 | 9µs | 1 | 3µs | $VERSION = sprintf "%d.%02d", q$Revision: 2.97 $ =~ /(\d+)/g; # spent 3µs making 1 call to Encode::CORE:match |
11 | 1 | 400ns | require XSLoader; | ||
12 | 1 | 213µs | 1 | 206µs | XSLoader::load( __PACKAGE__, $VERSION ); # spent 206µs making 1 call to XSLoader::load |
13 | 1 | 32µs | 1 | 223µs | } # spent 223µs making 1 call to Encode::BEGIN@9 |
14 | |||||
15 | 3 | 162µs | 3 | 97µs | # spent 54µs (11+43) within Encode::BEGIN@15 which was called:
# once (11µs+43µs) by RBM::BEGIN@6 at line 15 # spent 54µs making 1 call to Encode::BEGIN@15
# spent 37µs making 1 call to UNIVERSAL::VERSION
# spent 6µs making 1 call to Exporter::import |
16 | |||||
17 | 1 | 1µs | our @CARP_NOT = qw(Encode::Encoder); | ||
18 | |||||
19 | # Public, encouraged API is exported by default | ||||
20 | |||||
21 | 1 | 2µs | our @EXPORT = qw( | ||
22 | decode decode_utf8 encode encode_utf8 str2bytes bytes2str | ||||
23 | encodings find_encoding find_mime_encoding clone_encoding | ||||
24 | ); | ||||
25 | 1 | 2µs | our @FB_FLAGS = qw( | ||
26 | DIE_ON_ERR WARN_ON_ERR RETURN_ON_ERR LEAVE_SRC | ||||
27 | PERLQQ HTMLCREF XMLCREF STOP_AT_PARTIAL | ||||
28 | ); | ||||
29 | 1 | 2µs | our @FB_CONSTS = qw( | ||
30 | FB_DEFAULT FB_CROAK FB_QUIET FB_WARN | ||||
31 | FB_PERLQQ FB_HTMLCREF FB_XMLCREF | ||||
32 | ); | ||||
33 | 1 | 3µs | our @EXPORT_OK = ( | ||
34 | qw( | ||||
35 | _utf8_off _utf8_on define_encoding from_to is_16bit is_8bit | ||||
36 | is_utf8 perlio_ok resolve_alias utf8_downgrade utf8_upgrade | ||||
37 | ), | ||||
38 | @FB_FLAGS, @FB_CONSTS, | ||||
39 | ); | ||||
40 | |||||
41 | 1 | 6µs | our %EXPORT_TAGS = ( | ||
42 | all => [ @EXPORT, @EXPORT_OK ], | ||||
43 | default => [ @EXPORT ], | ||||
44 | fallbacks => [ @FB_CONSTS ], | ||||
45 | fallback_all => [ @FB_CONSTS, @FB_FLAGS ], | ||||
46 | ); | ||||
47 | |||||
48 | # Documentation moved after __END__ for speed - NI-S | ||||
49 | |||||
50 | 1 | 300ns | our $ON_EBCDIC = ( ord("A") == 193 ); | ||
51 | |||||
52 | 2 | 90µs | 1 | 2.14ms | # spent 2.14ms (1.71+424µs) within Encode::BEGIN@52 which was called:
# once (1.71ms+424µs) by RBM::BEGIN@6 at line 52 # spent 2.14ms making 1 call to Encode::BEGIN@52 |
53 | 2 | 107µs | 2 | 578µs | # spent 577µs (539+38) within Encode::BEGIN@53 which was called:
# once (539µs+38µs) by RBM::BEGIN@6 at line 53 # spent 577µs making 1 call to Encode::BEGIN@53
# spent 800ns making 1 call to Encode::__ANON__ |
54 | |||||
55 | 2 | 1.88ms | 2 | 5.21ms | # spent 5.18ms (2.36+2.82) within Encode::BEGIN@55 which was called:
# once (2.36ms+2.82ms) by RBM::BEGIN@6 at line 55 # spent 5.18ms making 1 call to Encode::BEGIN@55
# spent 36µs making 1 call to Exporter::import |
56 | |||||
57 | # Make a %Encoding package variable to allow a certain amount of cheating | ||||
58 | our %Encoding; | ||||
59 | our %ExtModule; | ||||
60 | 1 | 103µs | require Encode::Config; | ||
61 | # See | ||||
62 | # https://bugzilla.redhat.com/show_bug.cgi?id=435505#c2 | ||||
63 | # to find why sig handlers inside eval{} are disabled. | ||||
64 | 1 | 200ns | eval { | ||
65 | 1 | 2µs | local $SIG{__DIE__}; | ||
66 | 1 | 1µs | local $SIG{__WARN__}; | ||
67 | 1 | 2µs | local @INC = @INC; | ||
68 | 1 | 300ns | pop @INC if $INC[-1] eq '.'; | ||
69 | 1 | 41µs | require Encode::ConfigLocal; | ||
70 | }; | ||||
71 | |||||
72 | sub encodings { | ||||
73 | my %enc; | ||||
74 | my $arg = $_[1] || ''; | ||||
75 | if ( $arg eq ":all" ) { | ||||
76 | %enc = ( %Encoding, %ExtModule ); | ||||
77 | } | ||||
78 | else { | ||||
79 | %enc = %Encoding; | ||||
80 | for my $mod ( map { m/::/ ? $_ : "Encode::$_" } @_ ) { | ||||
81 | DEBUG and warn $mod; | ||||
82 | for my $enc ( keys %ExtModule ) { | ||||
83 | $ExtModule{$enc} eq $mod and $enc{$enc} = $mod; | ||||
84 | } | ||||
85 | } | ||||
86 | } | ||||
87 | return sort { lc $a cmp lc $b } | ||||
88 | grep { !/^(?:Internal|Unicode|Guess)$/o } keys %enc; | ||||
89 | } | ||||
90 | |||||
91 | sub perlio_ok { | ||||
92 | my $obj = ref( $_[0] ) ? $_[0] : find_encoding( $_[0] ); | ||||
93 | $obj->can("perlio_ok") and return $obj->perlio_ok(); | ||||
94 | return 0; # safety net | ||||
95 | } | ||||
96 | |||||
97 | sub define_encoding { | ||||
98 | 8 | 1µs | my $obj = shift; | ||
99 | 8 | 2µs | my $name = shift; | ||
100 | 8 | 5µs | $Encoding{$name} = $obj; | ||
101 | 8 | 3µs | my $lc = lc($name); | ||
102 | 8 | 3µs | 1 | 2µs | define_alias( $lc => $obj ) unless $lc eq $name; # spent 2µs making 1 call to Encode::define_alias |
103 | 8 | 2µs | while (@_) { | ||
104 | my $alias = shift; | ||||
105 | define_alias( $alias, $obj ); | ||||
106 | } | ||||
107 | 8 | 2µs | my $class = ref($obj); | ||
108 | 8 | 6µs | push @Encode::CARP_NOT, $class unless grep { $_ eq $class } @Encode::CARP_NOT; | ||
109 | 8 | 7µs | push @Encode::Encoding::CARP_NOT, $class unless grep { $_ eq $class } @Encode::Encoding::CARP_NOT; | ||
110 | 8 | 13µs | return $obj; | ||
111 | } | ||||
112 | |||||
113 | # spent 74.7ms (62.0+12.7) within Encode::getEncoding which was called 5051 times, avg 15µs/call:
# 5051 times (62.0ms+12.7ms) by Encode::find_encoding at line 152, avg 15µs/call | ||||
114 | 5051 | 4.68ms | my ( $class, $name, $skip_external ) = @_; | ||
115 | |||||
116 | 5051 | 3.04ms | defined($name) or return; | ||
117 | |||||
118 | 5051 | 39.1ms | 5051 | 12.7ms | $name =~ s/\s+//g; # https://rt.cpan.org/Ticket/Display.html?id=65796 # spent 12.7ms making 5051 calls to Encode::CORE:subst, avg 3µs/call |
119 | |||||
120 | 5051 | 3.56ms | ref($name) && $name->can('renew') and return $name; | ||
121 | 5051 | 33.0ms | exists $Encoding{$name} and return $Encoding{$name}; | ||
122 | my $lc = lc $name; | ||||
123 | exists $Encoding{$lc} and return $Encoding{$lc}; | ||||
124 | |||||
125 | my $oc = $class->find_alias($name); | ||||
126 | defined($oc) and return $oc; | ||||
127 | $lc ne $name and $oc = $class->find_alias($lc); | ||||
128 | defined($oc) and return $oc; | ||||
129 | |||||
130 | unless ($skip_external) { | ||||
131 | if ( my $mod = $ExtModule{$name} || $ExtModule{$lc} ) { | ||||
132 | $mod =~ s,::,/,g; | ||||
133 | $mod .= '.pm'; | ||||
134 | eval { require $mod; }; | ||||
135 | exists $Encoding{$name} and return $Encoding{$name}; | ||||
136 | } | ||||
137 | } | ||||
138 | return; | ||||
139 | } | ||||
140 | |||||
141 | # HACK: These two functions must be defined in Encode and because of | ||||
142 | # cyclic dependency between Encode and Encode::Alias, Exporter does not work | ||||
143 | sub find_alias { | ||||
144 | goto &Encode::Alias::find_alias; | ||||
145 | } | ||||
146 | # spent 2µs within Encode::define_alias which was called:
# once (2µs+0s) by Encode::define_encoding at line 102 | ||||
147 | 1 | 6µs | 1 | 7µs | goto &Encode::Alias::define_alias; # spent 7µs making 1 call to Encode::Alias::define_alias |
148 | } | ||||
149 | |||||
150 | sub find_encoding($;$) { | ||||
151 | 5051 | 3.54ms | my ( $name, $skip_external ) = @_; | ||
152 | 5051 | 56.7ms | 5051 | 74.7ms | return __PACKAGE__->getEncoding( $name, $skip_external ); # spent 74.7ms making 5051 calls to Encode::getEncoding, avg 15µs/call |
153 | } | ||||
154 | |||||
155 | sub find_mime_encoding($;$) { | ||||
156 | my ( $mime_name, $skip_external ) = @_; | ||||
157 | my $name = Encode::MIME::Name::get_encode_name( $mime_name ); | ||||
158 | return find_encoding( $name, $skip_external ); | ||||
159 | } | ||||
160 | |||||
161 | sub resolve_alias($) { | ||||
162 | my $obj = find_encoding(shift); | ||||
163 | defined $obj and return $obj->name; | ||||
164 | return; | ||||
165 | } | ||||
166 | |||||
167 | sub clone_encoding($) { | ||||
168 | my $obj = find_encoding(shift); | ||||
169 | ref $obj or return; | ||||
170 | return Storable::dclone($obj); | ||||
171 | } | ||||
172 | |||||
173 | # spent 252ms (122+129) within Encode::encode which was called 4038 times, avg 62µs/call:
# 4038 times (122ms+129ms) by RBM::__ANON__[rbm/lib/RBM.pm:667] at line 666 of /root/tor-browser-build/rbm/lib/RBM.pm, avg 62µs/call | ||||
174 | 4038 | 7.08ms | my ( $name, $string, $check ) = @_; | ||
175 | 4038 | 1.71ms | return undef unless defined $string; | ||
176 | 4038 | 18.1ms | $string .= ''; # stringify; | ||
177 | 4038 | 3.81ms | $check ||= 0; | ||
178 | 4038 | 2.81ms | unless ( defined $name ) { | ||
179 | require Carp; | ||||
180 | Carp::croak("Encoding name should not be undef"); | ||||
181 | } | ||||
182 | 4038 | 14.9ms | 4038 | 108ms | my $enc = find_encoding($name); # spent 108ms making 4038 calls to Encode::find_encoding, avg 27µs/call |
183 | 4038 | 3.07ms | unless ( defined $enc ) { | ||
184 | require Carp; | ||||
185 | Carp::croak("Unknown encoding '$name'"); | ||||
186 | } | ||||
187 | # For Unicode, warnings need to be caught and re-issued at this level | ||||
188 | # so that callers can disable utf8 warnings lexically. | ||||
189 | 4038 | 1.80ms | my $octets; | ||
190 | 4038 | 11.7ms | if ( ref($enc) eq 'Encode::Unicode' ) { | ||
191 | my $warn = ''; | ||||
192 | { | ||||
193 | local $SIG{__WARN__} = sub { $warn = shift }; | ||||
194 | $octets = $enc->encode( $string, $check ); | ||||
195 | } | ||||
196 | warnings::warnif('utf8', $warn) if length $warn; | ||||
197 | } | ||||
198 | else { | ||||
199 | 4038 | 54.1ms | 4038 | 21.5ms | $octets = $enc->encode( $string, $check ); # spent 21.5ms making 4038 calls to Encode::utf8::encode, avg 5µs/call |
200 | } | ||||
201 | 4038 | 2.75ms | $_[1] = $string if $check and !ref $check and !( $check & LEAVE_SRC ); | ||
202 | 4038 | 19.1ms | return $octets; | ||
203 | } | ||||
204 | 1 | 2µs | *str2bytes = \&encode; | ||
205 | |||||
206 | # spent 79.3ms (37.8+41.5) within Encode::decode which was called 1013 times, avg 78µs/call:
# 1013 times (37.8ms+41.5ms) by Template::Provider::_decode_unicode at line 1114 of Template/Provider.pm, avg 78µs/call | ||||
207 | 1013 | 4.25ms | my ( $name, $octets, $check ) = @_; | ||
208 | 1013 | 849µs | return undef unless defined $octets; | ||
209 | 1013 | 1.92ms | $octets .= ''; | ||
210 | 1013 | 938µs | $check ||= 0; | ||
211 | 1013 | 3.42ms | 1013 | 26.8ms | my $enc = find_encoding($name); # spent 26.8ms making 1013 calls to Encode::find_encoding, avg 26µs/call |
212 | 1013 | 979µs | unless ( defined $enc ) { | ||
213 | require Carp; | ||||
214 | Carp::croak("Unknown encoding '$name'"); | ||||
215 | } | ||||
216 | # For Unicode, warnings need to be caught and re-issued at this level | ||||
217 | # so that callers can disable utf8 warnings lexically. | ||||
218 | 1013 | 346µs | my $string; | ||
219 | 1013 | 2.55ms | if ( ref($enc) eq 'Encode::Unicode' ) { | ||
220 | my $warn = ''; | ||||
221 | { | ||||
222 | local $SIG{__WARN__} = sub { $warn = shift }; | ||||
223 | $string = $enc->decode( $octets, $check ); | ||||
224 | } | ||||
225 | warnings::warnif('utf8', $warn) if length $warn; | ||||
226 | } | ||||
227 | else { | ||||
228 | 1013 | 21.6ms | 2026 | 18.7ms | $string = $enc->decode( $octets, $check ); # spent 14.7ms making 1013 calls to Encode::utf8::decode, avg 15µs/call
# spent 3.97ms making 1013 calls to Encode::Encoding::renewed, avg 4µs/call |
229 | } | ||||
230 | 1013 | 484µs | $_[1] = $octets if $check and !ref $check and !( $check & LEAVE_SRC ); | ||
231 | 1013 | 3.38ms | return $string; | ||
232 | } | ||||
233 | 1 | 400ns | *bytes2str = \&decode; | ||
234 | |||||
235 | sub from_to($$$;$) { | ||||
236 | my ( $string, $from, $to, $check ) = @_; | ||||
237 | return undef unless defined $string; | ||||
238 | $check ||= 0; | ||||
239 | my $f = find_encoding($from); | ||||
240 | unless ( defined $f ) { | ||||
241 | require Carp; | ||||
242 | Carp::croak("Unknown encoding '$from'"); | ||||
243 | } | ||||
244 | my $t = find_encoding($to); | ||||
245 | unless ( defined $t ) { | ||||
246 | require Carp; | ||||
247 | Carp::croak("Unknown encoding '$to'"); | ||||
248 | } | ||||
249 | |||||
250 | # For Unicode, warnings need to be caught and re-issued at this level | ||||
251 | # so that callers can disable utf8 warnings lexically. | ||||
252 | my $uni; | ||||
253 | if ( ref($f) eq 'Encode::Unicode' ) { | ||||
254 | my $warn = ''; | ||||
255 | { | ||||
256 | local $SIG{__WARN__} = sub { $warn = shift }; | ||||
257 | $uni = $f->decode($string); | ||||
258 | } | ||||
259 | warnings::warnif('utf8', $warn) if length $warn; | ||||
260 | } | ||||
261 | else { | ||||
262 | $uni = $f->decode($string); | ||||
263 | } | ||||
264 | |||||
265 | if ( ref($t) eq 'Encode::Unicode' ) { | ||||
266 | my $warn = ''; | ||||
267 | { | ||||
268 | local $SIG{__WARN__} = sub { $warn = shift }; | ||||
269 | $_[0] = $string = $t->encode( $uni, $check ); | ||||
270 | } | ||||
271 | warnings::warnif('utf8', $warn) if length $warn; | ||||
272 | } | ||||
273 | else { | ||||
274 | $_[0] = $string = $t->encode( $uni, $check ); | ||||
275 | } | ||||
276 | |||||
277 | return undef if ( $check && length($uni) ); | ||||
278 | return defined( $_[0] ) ? length($string) : undef; | ||||
279 | } | ||||
280 | |||||
281 | sub encode_utf8($) { | ||||
282 | my ($str) = @_; | ||||
283 | return undef unless defined $str; | ||||
284 | utf8::encode($str); | ||||
285 | return $str; | ||||
286 | } | ||||
287 | |||||
288 | 1 | 100ns | my $utf8enc; | ||
289 | |||||
290 | sub decode_utf8($;$) { | ||||
291 | my ( $octets, $check ) = @_; | ||||
292 | return undef unless defined $octets; | ||||
293 | $octets .= ''; | ||||
294 | $check ||= 0; | ||||
295 | $utf8enc ||= find_encoding('utf8'); | ||||
296 | my $string = $utf8enc->decode( $octets, $check ); | ||||
297 | $_[0] = $octets if $check and !ref $check and !( $check & LEAVE_SRC ); | ||||
298 | return $string; | ||||
299 | } | ||||
300 | |||||
301 | 1 | 27µs | 6 | 73µs | onBOOT; # spent 50µs making 1 call to Encode::onBOOT
# spent 23µs making 5 calls to Encode::define_encoding, avg 5µs/call |
302 | |||||
303 | 1 | 500ns | if ($ON_EBCDIC) { | ||
304 | package Encode::UTF_EBCDIC; | ||||
305 | 2 | 273µs | 2 | 2.27ms | # spent 1.55ms (268µs+1.28) within Encode::UTF_EBCDIC::BEGIN@305 which was called:
# once (268µs+1.28ms) by RBM::BEGIN@6 at line 305 # spent 1.55ms making 1 call to Encode::UTF_EBCDIC::BEGIN@305
# spent 717µs making 1 call to parent::import |
306 | my $obj = bless { Name => "UTF_EBCDIC" } => "Encode::UTF_EBCDIC"; | ||||
307 | Encode::define_encoding($obj, 'Unicode'); | ||||
308 | sub decode { | ||||
309 | my ( undef, $str, $chk ) = @_; | ||||
310 | my $res = ''; | ||||
311 | for ( my $i = 0 ; $i < length($str) ; $i++ ) { | ||||
312 | $res .= | ||||
313 | chr( | ||||
314 | utf8::unicode_to_native( ord( substr( $str, $i, 1 ) ) ) | ||||
315 | ); | ||||
316 | } | ||||
317 | $_[1] = '' if $chk; | ||||
318 | return $res; | ||||
319 | } | ||||
320 | sub encode { | ||||
321 | my ( undef, $str, $chk ) = @_; | ||||
322 | my $res = ''; | ||||
323 | for ( my $i = 0 ; $i < length($str) ; $i++ ) { | ||||
324 | $res .= | ||||
325 | chr( | ||||
326 | utf8::native_to_unicode( ord( substr( $str, $i, 1 ) ) ) | ||||
327 | ); | ||||
328 | } | ||||
329 | $_[1] = '' if $chk; | ||||
330 | return $res; | ||||
331 | } | ||||
332 | } else { | ||||
333 | package Encode::Internal; | ||||
334 | 2 | 132µs | 2 | 35µs | # spent 21µs (6+14) within Encode::Internal::BEGIN@334 which was called:
# once (6µs+14µs) by RBM::BEGIN@6 at line 334 # spent 21µs making 1 call to Encode::Internal::BEGIN@334
# spent 14µs making 1 call to parent::import |
335 | 1 | 1µs | my $obj = bless { Name => "Internal" } => "Encode::Internal"; | ||
336 | 1 | 600ns | 1 | 18µs | Encode::define_encoding($obj, 'Unicode'); # spent 18µs making 1 call to Encode::define_encoding |
337 | sub decode { | ||||
338 | my ( undef, $str, $chk ) = @_; | ||||
339 | utf8::upgrade($str); | ||||
340 | $_[1] = '' if $chk; | ||||
341 | return $str; | ||||
342 | } | ||||
343 | 1 | 700ns | *encode = \&decode; | ||
344 | } | ||||
345 | |||||
346 | { | ||||
347 | # https://rt.cpan.org/Public/Bug/Display.html?id=103253 | ||||
348 | package Encode::XS; | ||||
349 | 2 | 30µs | 2 | 33µs | # spent 19µs (6+14) within Encode::XS::BEGIN@349 which was called:
# once (6µs+14µs) by RBM::BEGIN@6 at line 349 # spent 19µs making 1 call to Encode::XS::BEGIN@349
# spent 14µs making 1 call to parent::import |
350 | } | ||||
351 | |||||
352 | { | ||||
353 | 1 | 300ns | package Encode::utf8; | ||
354 | 2 | 86µs | 2 | 33µs | # spent 22µs (12+10) within Encode::utf8::BEGIN@354 which was called:
# once (12µs+10µs) by RBM::BEGIN@6 at line 354 # spent 22µs making 1 call to Encode::utf8::BEGIN@354
# spent 10µs making 1 call to parent::import |
355 | 1 | 2µs | my %obj = ( | ||
356 | 'utf8' => { Name => 'utf8' }, | ||||
357 | 'utf-8-strict' => { Name => 'utf-8-strict', strict_utf8 => 1 } | ||||
358 | ); | ||||
359 | 1 | 2µs | for ( keys %obj ) { | ||
360 | 2 | 900ns | bless $obj{$_} => __PACKAGE__; | ||
361 | 2 | 2µs | 2 | 8µs | Encode::define_encoding( $obj{$_} => $_ ); # spent 8µs making 2 calls to Encode::define_encoding, avg 4µs/call |
362 | } | ||||
363 | sub cat_decode { | ||||
364 | # ($obj, $dst, $src, $pos, $trm, $chk) | ||||
365 | # currently ignores $chk | ||||
366 | my ( undef, undef, undef, $pos, $trm ) = @_; | ||||
367 | my ( $rdst, $rsrc, $rpos ) = \@_[ 1, 2, 3 ]; | ||||
368 | 2 | 341µs | 2 | 221µs | # spent 219µs (217+2) within Encode::utf8::BEGIN@368 which was called:
# once (217µs+2µs) by RBM::BEGIN@6 at line 368 # spent 219µs making 1 call to Encode::utf8::BEGIN@368
# spent 2µs making 1 call to bytes::import |
369 | if ( ( my $npos = index( $$rsrc, $trm, $pos ) ) >= 0 ) { | ||||
370 | $$rdst .= | ||||
371 | substr( $$rsrc, $pos, $npos - $pos + length($trm) ); | ||||
372 | $$rpos = $npos + length($trm); | ||||
373 | return 1; | ||||
374 | } | ||||
375 | $$rdst .= substr( $$rsrc, $pos ); | ||||
376 | $$rpos = length($$rsrc); | ||||
377 | return ''; | ||||
378 | } | ||||
379 | } | ||||
380 | |||||
381 | 2 | 25µs | 1; | ||
382 | |||||
383 | __END__ | ||||
# spent 3µs within Encode::CORE:match which was called:
# once (3µs+0s) by Encode::BEGIN@9 at line 10 | |||||
# spent 12.7ms within Encode::CORE:subst which was called 5051 times, avg 3µs/call:
# 5051 times (12.7ms+0s) by Encode::getEncoding at line 118, avg 3µs/call | |||||
# spent 800ns within Encode::__ANON__ which was called:
# once (800ns+0s) by Encode::BEGIN@53 at line 53 | |||||
# spent 2.33ms within Encode::is_utf8 which was called 1013 times, avg 2µs/call:
# 1013 times (2.33ms+0s) by Template::Provider::_decode_unicode at line 1095 of Template/Provider.pm, avg 2µs/call | |||||
# spent 50µs (28+23) within Encode::onBOOT which was called:
# once (28µs+23µs) by RBM::BEGIN@6 at line 301 | |||||
# spent 14.7ms (10.8+3.97) within Encode::utf8::decode which was called 1013 times, avg 15µs/call:
# 1013 times (10.8ms+3.97ms) by Encode::decode at line 228, avg 15µs/call | |||||
# spent 21.5ms within Encode::utf8::encode which was called 4038 times, avg 5µs/call:
# 4038 times (21.5ms+0s) by Encode::encode at line 199, avg 5µs/call |