← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 18:42:36 2015
Reported on Fri Jul 31 18:48:13 2015

Filename/usr/lib64/perl5/vendor_perl/Encode.pm
StatementsExecuted 4015491 statements in 6.03s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
132011111.32s2.61sEncode::::encode Encode::encode
126791111.32s2.93sEncode::::decode Encode::decode
258905641.26s1.92sEncode::::find_encoding Encode::find_encoding (recurses: max depth 1, inclusive time 14µs)
25890511657ms658msEncode::::getEncoding Encode::getEncoding (recurses: max depth 1, inclusive time 6µs)
1267911169.0ms69.0msEncode::::LEAVE_SRC Encode::LEAVE_SRC (xsub)
1267911161.0ms61.0msEncode::::FB_CROAK Encode::FB_CROAK (xsub)
296224.50ms4.87msEncode::utf8::::decode_xs Encode::utf8::decode_xs (xsub)
1112.23ms3.05msEncode::::BEGIN@48 Encode::BEGIN@48
111709µs764µsEncode::::predefine_encodings Encode::predefine_encodings
11333578µs697µsEncode::::encode_utf8 Encode::encode_utf8
111279µs283µsEncode::utf8::::BEGIN@325 Encode::utf8::BEGIN@325
41126µs26µsEncode::::define_encoding Encode::define_encoding
11120µs62µsEncode::::decode_utf8 Encode::decode_utf8
11117µs34µsEncode::::BEGIN@242 Encode::BEGIN@242
11116µs34µsEncode::::BEGIN@5 Encode::BEGIN@5
11113µs53µsEncode::::BEGIN@8 Encode::BEGIN@8
11112µs18µsEncode::::BEGIN@6 Encode::BEGIN@6
11111µs98µsEncode::::BEGIN@13 Encode::BEGIN@13
1115µs5µsEncode::::is_utf8 Encode::is_utf8 (xsub)
1115µs5µsEncode::::BEGIN@9 Encode::BEGIN@9
2224µs4µsEncode::::PERLQQ Encode::PERLQQ (xsub)
1113µs3µsEncode::utf8::::encode_xs Encode::utf8::encode_xs (xsub)
111700ns700nsEncode::::WARN_ON_ERR Encode::WARN_ON_ERR (xsub)
111600ns600nsEncode::::STOP_AT_PARTIAL Encode::STOP_AT_PARTIAL (xsub)
0000s0sEncode::Internal::::__ANON__[:285] Encode::Internal::__ANON__[:285]
0000s0sEncode::UTF_EBCDIC::::__ANON__[:260]Encode::UTF_EBCDIC::__ANON__[:260]
0000s0sEncode::UTF_EBCDIC::::__ANON__[:272]Encode::UTF_EBCDIC::__ANON__[:272]
0000s0sEncode::::clone_encoding Encode::clone_encoding
0000s0sEncode::::encodings Encode::encodings
0000s0sEncode::::from_to Encode::from_to
0000s0sEncode::::perlio_ok Encode::perlio_ok
0000s0sEncode::::resolve_alias Encode::resolve_alias
0000s0sEncode::utf8::::__ANON__[:313] Encode::utf8::__ANON__[:313]
0000s0sEncode::utf8::::__ANON__[:319] Encode::utf8::__ANON__[:319]
0000s0sEncode::utf8::::__ANON__[:335] Encode::utf8::__ANON__[:335]
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1#
2# $Id: Encode.pm,v 2.51 2013/04/29 22:19:11 dankogai Exp dankogai $
3#
4package Encode;
5235µs251µs
# spent 34µs (16+18) within Encode::BEGIN@5 which was called: # once (16µs+18µs) by Foswiki::Configure::Load::BEGIN@21 at line 5
use strict;
# spent 34µs making 1 call to Encode::BEGIN@5 # spent 18µs making 1 call to strict::import
6276µs224µs
# spent 18µs (12+6) within Encode::BEGIN@6 which was called: # once (12µs+6µs) by Foswiki::Configure::Load::BEGIN@21 at line 6
use warnings;
# spent 18µs making 1 call to Encode::BEGIN@6 # spent 6µs making 1 call to warnings::import
718µsour $VERSION = sprintf "%d.%02d", q$Revision: 2.51 $ =~ /(\d+)/g;
8240µs293µs
# spent 53µs (13+40) within Encode::BEGIN@8 which was called: # once (13µs+40µs) by Foswiki::Configure::Load::BEGIN@21 at line 8
use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG};
# spent 53µs making 1 call to Encode::BEGIN@8 # spent 40µs making 1 call to constant::import
9251µs15µs
# spent 5µs within Encode::BEGIN@9 which was called: # once (5µs+0s) by Foswiki::Configure::Load::BEGIN@21 at line 9
use XSLoader ();
# spent 5µs making 1 call to Encode::BEGIN@9
101246µs1288µsXSLoader::load( __PACKAGE__, $VERSION );
# spent 288µs making 1 call to XSLoader::load
11
121700nsrequire Exporter;
132187µs2186µs
# spent 98µs (11+88) within Encode::BEGIN@13 which was called: # once (11µs+88µs) by Foswiki::Configure::Load::BEGIN@21 at line 13
use base qw/Exporter/;
# spent 98µs making 1 call to Encode::BEGIN@13 # spent 88µs making 1 call to base::import
14
15# Public, encouraged API is exported by default
16
1712µsour @EXPORT = qw(
18 decode decode_utf8 encode encode_utf8 str2bytes bytes2str
19 encodings find_encoding clone_encoding
20);
2112µsour @FB_FLAGS = qw(
22 DIE_ON_ERR WARN_ON_ERR RETURN_ON_ERR LEAVE_SRC
23 PERLQQ HTMLCREF XMLCREF STOP_AT_PARTIAL
24);
2512µsour @FB_CONSTS = qw(
26 FB_DEFAULT FB_CROAK FB_QUIET FB_WARN
27 FB_PERLQQ FB_HTMLCREF FB_XMLCREF
28);
2915µsour @EXPORT_OK = (
30 qw(
31 _utf8_off _utf8_on define_encoding from_to is_16bit is_8bit
32 is_utf8 perlio_ok resolve_alias utf8_downgrade utf8_upgrade
33 ),
34 @FB_FLAGS, @FB_CONSTS,
35);
36
37121µsour %EXPORT_TAGS = (
38 all => [ @EXPORT, @EXPORT_OK ],
39 default => [ @EXPORT ],
40 fallbacks => [ @FB_CONSTS ],
41 fallback_all => [ @FB_CONSTS, @FB_FLAGS ],
42);
43
44# Documentation moved after __END__ for speed - NI-S
45
461500nsour $ON_EBCDIC = ( ord("A") == 193 );
47
4821.62ms23.08ms
# spent 3.05ms (2.23+813µs) within Encode::BEGIN@48 which was called: # once (2.23ms+813µs) by Foswiki::Configure::Load::BEGIN@21 at line 48
use Encode::Alias;
# spent 3.05ms making 1 call to Encode::BEGIN@48 # spent 30µs making 1 call to Exporter::import
49
50# Make a %Encoding package variable to allow a certain amount of cheating
511200nsour %Encoding;
521200nsour %ExtModule;
531174µsrequire Encode::Config;
54# See
55# https://bugzilla.redhat.com/show_bug.cgi?id=435505#c2
56# to find why sig handers inside eval{} are disabled.
571400nseval {
5813µs local $SIG{__DIE__};
591900ns local $SIG{__WARN__};
60150µs require Encode::ConfigLocal;
61};
62
63sub encodings {
64 my %enc;
65 my $arg = $_[1] || '';
66 if ( $arg eq ":all" ) {
67 %enc = ( %Encoding, %ExtModule );
68 }
69 else {
70 %enc = %Encoding;
71 for my $mod ( map { m/::/ ? $_ : "Encode::$_" } @_ ) {
72 DEBUG and warn $mod;
73 for my $enc ( keys %ExtModule ) {
74 $ExtModule{$enc} eq $mod and $enc{$enc} = $mod;
75 }
76 }
77 }
78 return sort { lc $a cmp lc $b }
79 grep { !/^(?:Internal|Unicode|Guess)$/o } keys %enc;
80}
81
82sub perlio_ok {
83 my $obj = ref( $_[0] ) ? $_[0] : find_encoding( $_[0] );
84 $obj->can("perlio_ok") and return $obj->perlio_ok();
85 return 0; # safety net
86}
87
88
# spent 26µs within Encode::define_encoding which was called 4 times, avg 7µs/call: # 4 times (26µs+0s) by XSLoader::load at line 92 of XSLoader.pm, avg 7µs/call
sub define_encoding {
8941µs my $obj = shift;
9041µs my $name = shift;
9144µs $Encoding{$name} = $obj;
9243µs my $lc = lc($name);
9341µs define_alias( $lc => $obj ) unless $lc eq $name;
9443µs while (@_) {
95 my $alias = shift;
96 define_alias( $alias, $obj );
97 }
98416µs return $obj;
99}
100
101
# spent 658ms (657+620µs) within Encode::getEncoding which was called 258905 times, avg 3µs/call: # 258905 times (657ms+620µs) by Encode::find_encoding at line 129, avg 3µs/call
sub getEncoding {
102258905118ms my ( $class, $name, $skip_external ) = @_;
103
104258905140ms $name =~ s/\s+//g; # https://rt.cpan.org/Ticket/Display.html?id=65796
105
10625890533.6ms ref($name) && $name->can('renew') and return $name;
107258905932ms exists $Encoding{$name} and return $Encoding{$name};
10810141µs my $lc = lc $name;
10910124µs exists $Encoding{$lc} and return $Encoding{$lc};
110
111101322µs101626µs my $oc = $class->find_alias($name);
# spent 626µs making 101 calls to Encode::Alias::find_alias, avg 6µs/call
112101241µs defined($oc) and return $oc;
113 $lc ne $name and $oc = $class->find_alias($lc);
114 defined($oc) and return $oc;
115
116 unless ($skip_external) {
117 if ( my $mod = $ExtModule{$name} || $ExtModule{$lc} ) {
118 $mod =~ s,::,/,g;
119 $mod .= '.pm';
120 eval { require $mod; };
121 exists $Encoding{$name} and return $Encoding{$name};
122 }
123 }
124 return;
125}
126
127
# spent 1.92s (1.26+658ms) within Encode::find_encoding which was called 258905 times, avg 7µs/call: # 132011 times (717ms+368ms) by Encode::encode at line 155, avg 8µs/call # 126791 times (547ms+288ms) by Encode::decode at line 171, avg 7µs/call # 100 times (470µs+1.54ms) by Foswiki::Templates::_readFile at line 589 of /var/www/foswikidev/core/lib/Foswiki/Templates.pm, avg 20µs/call # once (6µs+11µs) by Foswiki::Logger::PlainFile::log at line 136 of /var/www/foswikidev/core/lib/Foswiki/Logger/PlainFile.pm # once (9µs+7µs) by Encode::decode_utf8 at line 216 # once (8µs+-8µs) by Encode::Alias::find_alias at line 46 of Encode/Alias.pm
sub find_encoding($;$) {
12825890588.5ms my ( $name, $skip_external ) = @_;
1292589051.20s258905658ms return __PACKAGE__->getEncoding( $name, $skip_external );
# spent 658ms making 258905 calls to Encode::getEncoding, avg 3µs/call, recursion: max depth 1, sum of overlapping time 6µs
130}
131
132sub resolve_alias($) {
133 my $obj = find_encoding(shift);
134 defined $obj and return $obj->name;
135 return;
136}
137
138sub clone_encoding($) {
139 my $obj = find_encoding(shift);
140 ref $obj or return;
141 eval { require Storable };
142 $@ and return;
143 return Storable::dclone($obj);
144}
145
146
# spent 2.61s (1.32+1.28) within Encode::encode which was called 132011 times, avg 20µs/call: # 132011 times (1.32s+1.28s) by Foswiki::Store::encode at line 278 of /var/www/foswikidev/core/lib/Foswiki/Store.pm, avg 20µs/call
sub encode($$;$) {
14713201165.7ms my ( $name, $string, $check ) = @_;
14813201118.2ms return undef unless defined $string;
14913201183.7ms $string .= ''; # stringify;
15013201117.9ms $check ||= 0;
15113201111.8ms unless ( defined $name ) {
152 require Carp;
153 Carp::croak("Encoding name should not be undef");
154 }
155132011129ms1320111.09s my $enc = find_encoding($name);
# spent 1.09s making 132011 calls to Encode::find_encoding, avg 8µs/call
15613201115.9ms unless ( defined $enc ) {
157 require Carp;
158 Carp::croak("Unknown encoding '$name'");
159 }
160132011602ms132011197ms my $octets = $enc->encode( $string, $check );
# spent 197ms making 132011 calls to Encode::XS::encode, avg 1µs/call
16113201158.6ms $_[1] = $string if $check and !ref $check and !( $check & LEAVE_SRC() );
162132011416ms return $octets;
163}
16412µs*str2bytes = \&encode;
165
166
# spent 2.93s (1.32+1.61) within Encode::decode which was called 126791 times, avg 23µs/call: # 126791 times (1.32s+1.61s) by Foswiki::Store::decode at line 259 of /var/www/foswikidev/core/lib/Foswiki/Store.pm, avg 23µs/call
sub decode($$;$) {
16712679166.2ms my ( $name, $octets, $check ) = @_;
16812679115.0ms return undef unless defined $octets;
16912679126.9ms $octets .= '';
17012679111.2ms $check ||= 0;
171126791109ms126791834ms my $enc = find_encoding($name);
# spent 834ms making 126791 calls to Encode::find_encoding, avg 7µs/call
17212679115.4ms unless ( defined $enc ) {
173 require Carp;
174 Carp::croak("Unknown encoding '$name'");
175 }
1761267911.06s126791706ms my $string = $enc->decode( $octets, $check );
# spent 706ms making 126791 calls to Encode::XS::decode, avg 6µs/call
177126791431ms12679169.0ms $_[1] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() );
# spent 69.0ms making 126791 calls to Encode::LEAVE_SRC, avg 544ns/call
178126791353ms return $string;
179}
1801600ns*bytes2str = \&decode;
181
182sub from_to($$$;$) {
183 my ( $string, $from, $to, $check ) = @_;
184 return undef unless defined $string;
185 $check ||= 0;
186 my $f = find_encoding($from);
187 unless ( defined $f ) {
188 require Carp;
189 Carp::croak("Unknown encoding '$from'");
190 }
191 my $t = find_encoding($to);
192 unless ( defined $t ) {
193 require Carp;
194 Carp::croak("Unknown encoding '$to'");
195 }
196 my $uni = $f->decode($string);
197 $_[0] = $string = $t->encode( $uni, $check );
198 return undef if ( $check && length($uni) );
199 return defined( $_[0] ) ? length($string) : undef;
200}
201
202
# spent 697µs (578+119) within Encode::encode_utf8 which was called 113 times, avg 6µs/call: # 72 times (217µs+54µs) by Foswiki::urlEncode at line 2966 of /var/www/foswikidev/core/lib/Foswiki.pm, avg 4µs/call # 40 times (337µs+64µs) by Foswiki::Search::searchWeb at line 344 of /var/www/foswikidev/core/lib/Foswiki/Search.pm, avg 10µs/call # once (24µs+900ns) by Foswiki::Response::print at line 430 of /var/www/foswikidev/core/lib/Foswiki/Response.pm
sub encode_utf8($) {
20311377µs my ($str) = @_;
204113391µs113119µs utf8::encode($str);
# spent 119µs making 113 calls to utf8::encode, avg 1µs/call
205113238µs return $str;
206}
207
2081300nsmy $utf8enc;
209
210
# spent 62µs (20+42) within Encode::decode_utf8 which was called: # once (20µs+42µs) by Foswiki::urlDecode at line 2984 of /var/www/foswikidev/core/lib/Foswiki.pm
sub decode_utf8($;$) {
21111µs my ( $octets, $check ) = @_;
212112µs15µs return $octets if is_utf8($octets);
# spent 5µs making 1 call to Encode::is_utf8
2131300ns return undef unless defined $octets;
2141900ns $octets .= '';
2151400ns $check ||= 0;
21612µs115µs $utf8enc ||= find_encoding('utf8');
# spent 15µs making 1 call to Encode::find_encoding
217122µs224µs my $string = $utf8enc->decode( $octets, $check );
# spent 21µs making 1 call to Encode::utf8::decode_xs # spent 3µs making 1 call to Encode::Encoding::renewed
2181300ns $_[0] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() );
21913µs return $string;
220}
221
222# sub decode_utf8($;$) {
223# my ( $str, $check ) = @_;
224# return $str if is_utf8($str);
225# if ($check) {
226# return decode( "utf8", $str, $check );
227# }
228# else {
229# return decode( "utf8", $str );
230# return $str;
231# }
232# }
233
23413µs1764µspredefine_encodings(1);
# spent 764µs making 1 call to Encode::predefine_encodings
235
236#
237# This is to restore %Encoding if really needed;
238#
239
240
# spent 764µs (709+55) within Encode::predefine_encodings which was called: # once (709µs+55µs) by Foswiki::Configure::Load::BEGIN@21 at line 234
sub predefine_encodings {
2411108µs require Encode::Encoding;
2422682µs250µs
# spent 34µs (17+17) within Encode::BEGIN@242 which was called: # once (17µs+17µs) by Foswiki::Configure::Load::BEGIN@21 at line 242
no warnings 'redefine';
# spent 34µs making 1 call to Encode::BEGIN@242 # spent 17µs making 1 call to warnings::unimport
2431700ns my $use_xs = shift;
2441600ns if ($ON_EBCDIC) {
245
246 # was in Encode::UTF_EBCDIC
247 package Encode::UTF_EBCDIC;
248 push @Encode::UTF_EBCDIC::ISA, 'Encode::Encoding';
249 *decode = sub {
250 my ( undef, $str, $chk ) = @_;
251 my $res = '';
252 for ( my $i = 0 ; $i < length($str) ; $i++ ) {
253 $res .=
254 chr(
255 utf8::unicode_to_native( ord( substr( $str, $i, 1 ) ) )
256 );
257 }
258 $_[1] = '' if $chk;
259 return $res;
260 };
261 *encode = sub {
262 my ( undef, $str, $chk ) = @_;
263 my $res = '';
264 for ( my $i = 0 ; $i < length($str) ; $i++ ) {
265 $res .=
266 chr(
267 utf8::native_to_unicode( ord( substr( $str, $i, 1 ) ) )
268 );
269 }
270 $_[1] = '' if $chk;
271 return $res;
272 };
273 $Encode::Encoding{Unicode} =
274 bless { Name => "UTF_EBCDIC" } => "Encode::UTF_EBCDIC";
275 }
276 else {
277
278 package Encode::Internal;
27918µs push @Encode::Internal::ISA, 'Encode::Encoding';
280 *decode = sub {
281 my ( undef, $str, $chk ) = @_;
282 utf8::upgrade($str);
283 $_[1] = '' if $chk;
284 return $str;
28517µs };
2861700ns *encode = \&decode;
28718µs $Encode::Encoding{Unicode} =
288 bless { Name => "Internal" } => "Encode::Internal";
289 }
290
291 {
292
293 # was in Encode::utf8
29417µs package Encode::utf8;
29514µs push @Encode::utf8::ISA, 'Encode::Encoding';
296
297 #
2981500ns if ($use_xs) {
299 Encode::DEBUG and warn __PACKAGE__, " XS on";
30011µs *decode = \&decode_xs;
3011600ns *encode = \&encode_xs;
302 }
303 else {
304 Encode::DEBUG and warn __PACKAGE__, " XS off";
305 *decode = sub {
306 my ( undef, $octets, $chk ) = @_;
307 my $str = Encode::decode_utf8($octets);
308 if ( defined $str ) {
309 $_[1] = '' if $chk;
310 return $str;
311 }
312 return undef;
313 };
314 *encode = sub {
315 my ( undef, $string, $chk ) = @_;
316 my $octets = Encode::encode_utf8($string);
317 $_[1] = '' if $chk;
318 return $octets;
319 };
320 }
321 *cat_decode = sub { # ($obj, $dst, $src, $pos, $trm, $chk)
322 # currently ignores $chk
323 my ( undef, undef, undef, $pos, $trm ) = @_;
324 my ( $rdst, $rsrc, $rpos ) = \@_[ 1, 2, 3 ];
3252471µs2287µs
# spent 283µs (279+4) within Encode::utf8::BEGIN@325 which was called: # once (279µs+4µs) by Foswiki::Configure::Load::BEGIN@21 at line 325
use bytes;
# spent 283µs making 1 call to Encode::utf8::BEGIN@325 # spent 4µs making 1 call to bytes::import
326 if ( ( my $npos = index( $$rsrc, $trm, $pos ) ) >= 0 ) {
327 $$rdst .=
328 substr( $$rsrc, $pos, $npos - $pos + length($trm) );
329 $$rpos = $npos + length($trm);
330 return 1;
331 }
332 $$rdst .= substr( $$rsrc, $pos );
333 $$rpos = length($$rsrc);
334 return '';
33514µs };
33615µs $Encode::Encoding{utf8} =
337 bless { Name => "utf8" } => "Encode::utf8";
33812µs $Encode::Encoding{"utf-8-strict"} =
339 bless { Name => "utf-8-strict", strict_utf8 => 1 }
340 => "Encode::utf8";
341 }
342}
343
344120µs1;
345
346__END__
 
# spent 61.0ms within Encode::FB_CROAK which was called 126791 times, avg 481ns/call: # 126791 times (61.0ms+0s) by Foswiki::Store::decode at line 259 of /var/www/foswikidev/core/lib/Foswiki/Store.pm, avg 481ns/call
sub Encode::FB_CROAK; # xsub
# spent 69.0ms within Encode::LEAVE_SRC which was called 126791 times, avg 544ns/call: # 126791 times (69.0ms+0s) by Encode::decode at line 177, avg 544ns/call
sub Encode::LEAVE_SRC; # xsub
# spent 4µs within Encode::PERLQQ which was called 2 times, avg 2µs/call: # once (3µs+0s) by XSLoader::load at line 92 of XSLoader.pm # once (800ns+0s) by PerlIO::import at line 16 of PerlIO/encoding.pm
sub Encode::PERLQQ; # xsub
# spent 600ns within Encode::STOP_AT_PARTIAL which was called: # once (600ns+0s) by PerlIO::import at line 16 of PerlIO/encoding.pm
sub Encode::STOP_AT_PARTIAL; # xsub
# spent 700ns within Encode::WARN_ON_ERR which was called: # once (700ns+0s) by PerlIO::import at line 16 of PerlIO/encoding.pm
sub Encode::WARN_ON_ERR; # xsub
# spent 5µs within Encode::is_utf8 which was called: # once (5µs+0s) by Encode::decode_utf8 at line 212
sub Encode::is_utf8; # xsub
# spent 4.87ms (4.50+376µs) within Encode::utf8::decode_xs which was called 296 times, avg 16µs/call: # 295 times (4.48ms+374µs) by Foswiki::Templates::_readFile at line 591 of /var/www/foswikidev/core/lib/Foswiki/Templates.pm, avg 16µs/call # once (19µs+3µs) by Encode::decode_utf8 at line 217
sub Encode::utf8::decode_xs; # xsub
# spent 3µs within Encode::utf8::encode_xs which was called: # once (3µs+0s) by Foswiki::Logger::PlainFile::log at line 139 of /var/www/foswikidev/core/lib/Foswiki/Logger/PlainFile.pm
sub Encode::utf8::encode_xs; # xsub