Filename | /usr/lib/x86_64-linux-gnu/perl/5.20/Encode.pm |
Statements | Executed 80 statements in 5.09ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 2.08ms | 2.52ms | BEGIN@47 | Encode::
1 | 1 | 1 | 973µs | 1.01ms | predefine_encodings | Encode::
4 | 1 | 1 | 16µs | 16µs | define_encoding | Encode::
1 | 1 | 1 | 12µs | 26µs | BEGIN@12 | Encode::
1 | 1 | 1 | 12µs | 21µs | BEGIN@5 | Encode::
1 | 1 | 1 | 10µs | 24µs | BEGIN@240 | Encode::
1 | 1 | 1 | 9µs | 12µs | BEGIN@323 | Encode::utf8::
1 | 1 | 1 | 8µs | 45µs | BEGIN@8 | Encode::
1 | 1 | 1 | 6µs | 10µs | BEGIN@6 | Encode::
1 | 1 | 1 | 4µs | 4µs | CORE:match (opcode) | Encode::
1 | 1 | 1 | 3µs | 3µs | BEGIN@9 | Encode::
0 | 0 | 0 | 0s | 0s | __ANON__[:283] | Encode::Internal::
0 | 0 | 0 | 0s | 0s | __ANON__[:258] | Encode::UTF_EBCDIC::
0 | 0 | 0 | 0s | 0s | __ANON__[:270] | Encode::UTF_EBCDIC::
0 | 0 | 0 | 0s | 0s | clone_encoding | Encode::
0 | 0 | 0 | 0s | 0s | decode | Encode::
0 | 0 | 0 | 0s | 0s | decode_utf8 | Encode::
0 | 0 | 0 | 0s | 0s | encode | Encode::
0 | 0 | 0 | 0s | 0s | encode_utf8 | Encode::
0 | 0 | 0 | 0s | 0s | encodings | Encode::
0 | 0 | 0 | 0s | 0s | find_encoding | Encode::
0 | 0 | 0 | 0s | 0s | from_to | Encode::
0 | 0 | 0 | 0s | 0s | getEncoding | Encode::
0 | 0 | 0 | 0s | 0s | perlio_ok | Encode::
0 | 0 | 0 | 0s | 0s | resolve_alias | Encode::
0 | 0 | 0 | 0s | 0s | __ANON__[:311] | Encode::utf8::
0 | 0 | 0 | 0s | 0s | __ANON__[:317] | Encode::utf8::
0 | 0 | 0 | 0s | 0s | __ANON__[:333] | Encode::utf8::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # | ||||
2 | # $Id: Encode.pm,v 2.60 2014/04/29 16:26:49 dankogai Exp dankogai $ | ||||
3 | # | ||||
4 | package Encode; | ||||
5 | 2 | 25µs | 2 | 31µs | # spent 21µs (12+10) within Encode::BEGIN@5 which was called:
# once (12µs+10µs) by Date::Manip::Base::BEGIN@24 at line 5 # spent 21µs making 1 call to Encode::BEGIN@5
# spent 10µs making 1 call to strict::import |
6 | 2 | 48µs | 2 | 14µs | # spent 10µs (6+4) within Encode::BEGIN@6 which was called:
# once (6µs+4µs) by Date::Manip::Base::BEGIN@24 at line 6 # spent 10µs making 1 call to Encode::BEGIN@6
# spent 4µs making 1 call to warnings::import |
7 | 1 | 10µs | 1 | 4µs | our $VERSION = sprintf "%d.%02d", q$Revision: 2.60_01 $ =~ /(\d+)/g; # spent 4µs making 1 call to Encode::CORE:match |
8 | 2 | 22µs | 2 | 83µs | # spent 45µs (8+38) within Encode::BEGIN@8 which was called:
# once (8µs+38µs) by Date::Manip::Base::BEGIN@24 at line 8 # spent 45µs making 1 call to Encode::BEGIN@8
# spent 38µs making 1 call to constant::import |
9 | 2 | 34µs | 1 | 3µs | # spent 3µs within Encode::BEGIN@9 which was called:
# once (3µs+0s) by Date::Manip::Base::BEGIN@24 at line 9 # spent 3µs making 1 call to Encode::BEGIN@9 |
10 | 1 | 169µs | 1 | 192µs | XSLoader::load( __PACKAGE__, $VERSION ); # spent 192µs making 1 call to XSLoader::load |
11 | |||||
12 | 3 | 128µs | 3 | 39µs | # spent 26µs (12+13) within Encode::BEGIN@12 which was called:
# once (12µs+13µs) by Date::Manip::Base::BEGIN@24 at line 12 # spent 26µs making 1 call to Encode::BEGIN@12
# spent 8µs making 1 call to version::_VERSION
# spent 6µs making 1 call to Exporter::import |
13 | |||||
14 | # Public, encouraged API is exported by default | ||||
15 | |||||
16 | 1 | 1µs | our @EXPORT = qw( | ||
17 | decode decode_utf8 encode encode_utf8 str2bytes bytes2str | ||||
18 | encodings find_encoding clone_encoding | ||||
19 | ); | ||||
20 | 1 | 500ns | our @FB_FLAGS = qw( | ||
21 | DIE_ON_ERR WARN_ON_ERR RETURN_ON_ERR LEAVE_SRC | ||||
22 | PERLQQ HTMLCREF XMLCREF STOP_AT_PARTIAL | ||||
23 | ); | ||||
24 | 1 | 600ns | our @FB_CONSTS = qw( | ||
25 | FB_DEFAULT FB_CROAK FB_QUIET FB_WARN | ||||
26 | FB_PERLQQ FB_HTMLCREF FB_XMLCREF | ||||
27 | ); | ||||
28 | 1 | 1µs | our @EXPORT_OK = ( | ||
29 | qw( | ||||
30 | _utf8_off _utf8_on define_encoding from_to is_16bit is_8bit | ||||
31 | is_utf8 perlio_ok resolve_alias utf8_downgrade utf8_upgrade | ||||
32 | ), | ||||
33 | @FB_FLAGS, @FB_CONSTS, | ||||
34 | ); | ||||
35 | |||||
36 | 1 | 5µs | our %EXPORT_TAGS = ( | ||
37 | all => [ @EXPORT, @EXPORT_OK ], | ||||
38 | default => [ @EXPORT ], | ||||
39 | fallbacks => [ @FB_CONSTS ], | ||||
40 | fallback_all => [ @FB_CONSTS, @FB_FLAGS ], | ||||
41 | ); | ||||
42 | |||||
43 | # Documentation moved after __END__ for speed - NI-S | ||||
44 | |||||
45 | 1 | 300ns | our $ON_EBCDIC = ( ord("A") == 193 ); | ||
46 | |||||
47 | 2 | 1.74ms | 2 | 2.54ms | # spent 2.52ms (2.08+435µs) within Encode::BEGIN@47 which was called:
# once (2.08ms+435µs) by Date::Manip::Base::BEGIN@24 at line 47 # spent 2.52ms making 1 call to Encode::BEGIN@47
# spent 23µs making 1 call to Exporter::import |
48 | |||||
49 | # Make a %Encoding package variable to allow a certain amount of cheating | ||||
50 | 1 | 100ns | our %Encoding; | ||
51 | 1 | 100ns | our %ExtModule; | ||
52 | 1 | 632µs | require Encode::Config; | ||
53 | # See | ||||
54 | # https://bugzilla.redhat.com/show_bug.cgi?id=435505#c2 | ||||
55 | # to find why sig handlers inside eval{} are disabled. | ||||
56 | 1 | 200ns | eval { | ||
57 | 1 | 2µs | local $SIG{__DIE__}; | ||
58 | 1 | 500ns | local $SIG{__WARN__}; | ||
59 | 1 | 1.07ms | require Encode::ConfigLocal; | ||
60 | }; | ||||
61 | |||||
62 | sub encodings { | ||||
63 | my %enc; | ||||
64 | my $arg = $_[1] || ''; | ||||
65 | if ( $arg eq ":all" ) { | ||||
66 | %enc = ( %Encoding, %ExtModule ); | ||||
67 | } | ||||
68 | else { | ||||
69 | %enc = %Encoding; | ||||
70 | for my $mod ( map { m/::/ ? $_ : "Encode::$_" } @_ ) { | ||||
71 | DEBUG and warn $mod; | ||||
72 | for my $enc ( keys %ExtModule ) { | ||||
73 | $ExtModule{$enc} eq $mod and $enc{$enc} = $mod; | ||||
74 | } | ||||
75 | } | ||||
76 | } | ||||
77 | return sort { lc $a cmp lc $b } | ||||
78 | grep { !/^(?:Internal|Unicode|Guess)$/o } keys %enc; | ||||
79 | } | ||||
80 | |||||
81 | sub perlio_ok { | ||||
82 | my $obj = ref( $_[0] ) ? $_[0] : find_encoding( $_[0] ); | ||||
83 | $obj->can("perlio_ok") and return $obj->perlio_ok(); | ||||
84 | return 0; # safety net | ||||
85 | } | ||||
86 | |||||
87 | # spent 16µs within Encode::define_encoding which was called 4 times, avg 4µs/call:
# 4 times (16µs+0s) by XSLoader::load at line 92 of XSLoader.pm, avg 4µs/call | ||||
88 | 4 | 800ns | my $obj = shift; | ||
89 | 4 | 700ns | my $name = shift; | ||
90 | 4 | 2µs | $Encoding{$name} = $obj; | ||
91 | 4 | 2µs | my $lc = lc($name); | ||
92 | 4 | 800ns | define_alias( $lc => $obj ) unless $lc eq $name; | ||
93 | 4 | 1µs | while (@_) { | ||
94 | my $alias = shift; | ||||
95 | define_alias( $alias, $obj ); | ||||
96 | } | ||||
97 | 4 | 8µs | return $obj; | ||
98 | } | ||||
99 | |||||
100 | sub getEncoding { | ||||
101 | my ( $class, $name, $skip_external ) = @_; | ||||
102 | |||||
103 | $name =~ s/\s+//g; # https://rt.cpan.org/Ticket/Display.html?id=65796 | ||||
104 | |||||
105 | ref($name) && $name->can('renew') and return $name; | ||||
106 | exists $Encoding{$name} and return $Encoding{$name}; | ||||
107 | my $lc = lc $name; | ||||
108 | exists $Encoding{$lc} and return $Encoding{$lc}; | ||||
109 | |||||
110 | my $oc = $class->find_alias($name); | ||||
111 | defined($oc) and return $oc; | ||||
112 | $lc ne $name and $oc = $class->find_alias($lc); | ||||
113 | defined($oc) and return $oc; | ||||
114 | |||||
115 | unless ($skip_external) { | ||||
116 | if ( my $mod = $ExtModule{$name} || $ExtModule{$lc} ) { | ||||
117 | $mod =~ s,::,/,g; | ||||
118 | $mod .= '.pm'; | ||||
119 | eval { require $mod; }; | ||||
120 | exists $Encoding{$name} and return $Encoding{$name}; | ||||
121 | } | ||||
122 | } | ||||
123 | return; | ||||
124 | } | ||||
125 | |||||
126 | sub find_encoding($;$) { | ||||
127 | my ( $name, $skip_external ) = @_; | ||||
128 | return __PACKAGE__->getEncoding( $name, $skip_external ); | ||||
129 | } | ||||
130 | |||||
131 | sub resolve_alias($) { | ||||
132 | my $obj = find_encoding(shift); | ||||
133 | defined $obj and return $obj->name; | ||||
134 | return; | ||||
135 | } | ||||
136 | |||||
137 | sub clone_encoding($) { | ||||
138 | my $obj = find_encoding(shift); | ||||
139 | ref $obj or return; | ||||
140 | eval { require Storable }; | ||||
141 | $@ and return; | ||||
142 | return Storable::dclone($obj); | ||||
143 | } | ||||
144 | |||||
145 | sub encode($$;$) { | ||||
146 | my ( $name, $string, $check ) = @_; | ||||
147 | return undef unless defined $string; | ||||
148 | $string .= ''; # stringify; | ||||
149 | $check ||= 0; | ||||
150 | unless ( defined $name ) { | ||||
151 | require Carp; | ||||
152 | Carp::croak("Encoding name should not be undef"); | ||||
153 | } | ||||
154 | my $enc = find_encoding($name); | ||||
155 | unless ( defined $enc ) { | ||||
156 | require Carp; | ||||
157 | Carp::croak("Unknown encoding '$name'"); | ||||
158 | } | ||||
159 | my $octets = $enc->encode( $string, $check ); | ||||
160 | $_[1] = $string if $check and !ref $check and !( $check & LEAVE_SRC() ); | ||||
161 | return $octets; | ||||
162 | } | ||||
163 | 1 | 1µs | *str2bytes = \&encode; | ||
164 | |||||
165 | sub decode($$;$) { | ||||
166 | my ( $name, $octets, $check ) = @_; | ||||
167 | return undef unless defined $octets; | ||||
168 | $octets .= ''; | ||||
169 | $check ||= 0; | ||||
170 | my $enc = find_encoding($name); | ||||
171 | unless ( defined $enc ) { | ||||
172 | require Carp; | ||||
173 | Carp::croak("Unknown encoding '$name'"); | ||||
174 | } | ||||
175 | my $string = $enc->decode( $octets, $check ); | ||||
176 | $_[1] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() ); | ||||
177 | return $string; | ||||
178 | } | ||||
179 | 1 | 300ns | *bytes2str = \&decode; | ||
180 | |||||
181 | sub from_to($$$;$) { | ||||
182 | my ( $string, $from, $to, $check ) = @_; | ||||
183 | return undef unless defined $string; | ||||
184 | $check ||= 0; | ||||
185 | my $f = find_encoding($from); | ||||
186 | unless ( defined $f ) { | ||||
187 | require Carp; | ||||
188 | Carp::croak("Unknown encoding '$from'"); | ||||
189 | } | ||||
190 | my $t = find_encoding($to); | ||||
191 | unless ( defined $t ) { | ||||
192 | require Carp; | ||||
193 | Carp::croak("Unknown encoding '$to'"); | ||||
194 | } | ||||
195 | my $uni = $f->decode($string); | ||||
196 | $_[0] = $string = $t->encode( $uni, $check ); | ||||
197 | return undef if ( $check && length($uni) ); | ||||
198 | return defined( $_[0] ) ? length($string) : undef; | ||||
199 | } | ||||
200 | |||||
201 | sub encode_utf8($) { | ||||
202 | my ($str) = @_; | ||||
203 | utf8::encode($str); | ||||
204 | return $str; | ||||
205 | } | ||||
206 | |||||
207 | 1 | 100ns | my $utf8enc; | ||
208 | |||||
209 | sub decode_utf8($;$) { | ||||
210 | my ( $octets, $check ) = @_; | ||||
211 | return undef unless defined $octets; | ||||
212 | $octets .= ''; | ||||
213 | $check ||= 0; | ||||
214 | $utf8enc ||= find_encoding('utf8'); | ||||
215 | my $string = $utf8enc->decode( $octets, $check ); | ||||
216 | $_[0] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() ); | ||||
217 | return $string; | ||||
218 | } | ||||
219 | |||||
220 | # sub decode_utf8($;$) { | ||||
221 | # my ( $str, $check ) = @_; | ||||
222 | # return $str if is_utf8($str); | ||||
223 | # if ($check) { | ||||
224 | # return decode( "utf8", $str, $check ); | ||||
225 | # } | ||||
226 | # else { | ||||
227 | # return decode( "utf8", $str ); | ||||
228 | # return $str; | ||||
229 | # } | ||||
230 | # } | ||||
231 | |||||
232 | 1 | 2µs | 1 | 1.01ms | predefine_encodings(1); # spent 1.01ms making 1 call to Encode::predefine_encodings |
233 | |||||
234 | # | ||||
235 | # This is to restore %Encoding if really needed; | ||||
236 | # | ||||
237 | |||||
238 | # spent 1.01ms (973µs+35µs) within Encode::predefine_encodings which was called:
# once (973µs+35µs) by Date::Manip::Base::BEGIN@24 at line 232 | ||||
239 | 1 | 608µs | require Encode::Encoding; | ||
240 | 2 | 424µs | 2 | 38µs | # spent 24µs (10+14) within Encode::BEGIN@240 which was called:
# once (10µs+14µs) by Date::Manip::Base::BEGIN@24 at line 240 # spent 24µs making 1 call to Encode::BEGIN@240
# spent 14µs making 1 call to warnings::unimport |
241 | 1 | 400ns | my $use_xs = shift; | ||
242 | 1 | 300ns | if ($ON_EBCDIC) { | ||
243 | |||||
244 | # was in Encode::UTF_EBCDIC | ||||
245 | package Encode::UTF_EBCDIC; | ||||
246 | push @Encode::UTF_EBCDIC::ISA, 'Encode::Encoding'; | ||||
247 | *decode = sub { | ||||
248 | my ( undef, $str, $chk ) = @_; | ||||
249 | my $res = ''; | ||||
250 | for ( my $i = 0 ; $i < length($str) ; $i++ ) { | ||||
251 | $res .= | ||||
252 | chr( | ||||
253 | utf8::unicode_to_native( ord( substr( $str, $i, 1 ) ) ) | ||||
254 | ); | ||||
255 | } | ||||
256 | $_[1] = '' if $chk; | ||||
257 | return $res; | ||||
258 | }; | ||||
259 | *encode = sub { | ||||
260 | my ( undef, $str, $chk ) = @_; | ||||
261 | my $res = ''; | ||||
262 | for ( my $i = 0 ; $i < length($str) ; $i++ ) { | ||||
263 | $res .= | ||||
264 | chr( | ||||
265 | utf8::native_to_unicode( ord( substr( $str, $i, 1 ) ) ) | ||||
266 | ); | ||||
267 | } | ||||
268 | $_[1] = '' if $chk; | ||||
269 | return $res; | ||||
270 | }; | ||||
271 | $Encode::Encoding{Unicode} = | ||||
272 | bless { Name => "UTF_EBCDIC" } => "Encode::UTF_EBCDIC"; | ||||
273 | } | ||||
274 | else { | ||||
275 | |||||
276 | package Encode::Internal; | ||||
277 | 1 | 4µs | push @Encode::Internal::ISA, 'Encode::Encoding'; | ||
278 | *decode = sub { | ||||
279 | my ( undef, $str, $chk ) = @_; | ||||
280 | utf8::upgrade($str); | ||||
281 | $_[1] = '' if $chk; | ||||
282 | return $str; | ||||
283 | 1 | 2µs | }; | ||
284 | 1 | 300ns | *encode = \&decode; | ||
285 | 1 | 1µs | $Encode::Encoding{Unicode} = | ||
286 | bless { Name => "Internal" } => "Encode::Internal"; | ||||
287 | } | ||||
288 | |||||
289 | { | ||||
290 | |||||
291 | # was in Encode::utf8 | ||||
292 | 1 | 4µs | package Encode::utf8; | ||
293 | 1 | 2µs | push @Encode::utf8::ISA, 'Encode::Encoding'; | ||
294 | |||||
295 | # | ||||
296 | 1 | 300ns | if ($use_xs) { | ||
297 | Encode::DEBUG and warn __PACKAGE__, " XS on"; | ||||
298 | 1 | 400ns | *decode = \&decode_xs; | ||
299 | 1 | 300ns | *encode = \&encode_xs; | ||
300 | } | ||||
301 | else { | ||||
302 | Encode::DEBUG and warn __PACKAGE__, " XS off"; | ||||
303 | *decode = sub { | ||||
304 | my ( undef, $octets, $chk ) = @_; | ||||
305 | my $str = Encode::decode_utf8($octets); | ||||
306 | if ( defined $str ) { | ||||
307 | $_[1] = '' if $chk; | ||||
308 | return $str; | ||||
309 | } | ||||
310 | return undef; | ||||
311 | }; | ||||
312 | *encode = sub { | ||||
313 | my ( undef, $string, $chk ) = @_; | ||||
314 | my $octets = Encode::encode_utf8($string); | ||||
315 | $_[1] = '' if $chk; | ||||
316 | return $octets; | ||||
317 | }; | ||||
318 | } | ||||
319 | *cat_decode = sub { # ($obj, $dst, $src, $pos, $trm, $chk) | ||||
320 | # currently ignores $chk | ||||
321 | my ( undef, undef, undef, $pos, $trm ) = @_; | ||||
322 | my ( $rdst, $rsrc, $rpos ) = \@_[ 1, 2, 3 ]; | ||||
323 | 2 | 126µs | 2 | 14µs | # spent 12µs (9+2) within Encode::utf8::BEGIN@323 which was called:
# once (9µs+2µs) by Date::Manip::Base::BEGIN@24 at line 323 # spent 12µs making 1 call to Encode::utf8::BEGIN@323
# spent 2µs making 1 call to bytes::import |
324 | if ( ( my $npos = index( $$rsrc, $trm, $pos ) ) >= 0 ) { | ||||
325 | $$rdst .= | ||||
326 | substr( $$rsrc, $pos, $npos - $pos + length($trm) ); | ||||
327 | $$rpos = $npos + length($trm); | ||||
328 | return 1; | ||||
329 | } | ||||
330 | $$rdst .= substr( $$rsrc, $pos ); | ||||
331 | $$rpos = length($$rsrc); | ||||
332 | return ''; | ||||
333 | 1 | 2µs | }; | ||
334 | 1 | 900ns | $Encode::Encoding{utf8} = | ||
335 | bless { Name => "utf8" } => "Encode::utf8"; | ||||
336 | 1 | 1µs | $Encode::Encoding{"utf-8-strict"} = | ||
337 | bless { Name => "utf-8-strict", strict_utf8 => 1 } | ||||
338 | => "Encode::utf8"; | ||||
339 | } | ||||
340 | } | ||||
341 | |||||
342 | 1 | 9µs | 1; | ||
343 | |||||
344 | __END__ | ||||
# spent 4µs within Encode::CORE:match which was called:
# once (4µs+0s) by Date::Manip::Base::BEGIN@24 at line 7 |