← Index
NYTProf Performance Profile   « line view »
For /usr/local/bin/sa-learn
  Run on Sun Nov 5 03:09:29 2017
Reported on Mon Nov 6 13:20:45 2017

Filename/usr/local/lib/perl5/5.24/mach/Encode.pm
StatementsExecuted 142 statements in 7.34ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1039119.69ms9.69msEncode::utf8::::encode_xs Encode::utf8::encode_xs (xsub)
1113.80ms6.39msEncode::::BEGIN@47 Encode::BEGIN@47
1111.34ms1.46msEncode::::predefine_encodings Encode::predefine_encodings
711169µs1.33msEncode::::getEncoding Encode::getEncoding (recurses: max depth 1, inclusive time 41µs)
511127µs127µsEncode::::define_encoding Encode::define_encoding
763124µs1.41msEncode::::find_encoding Encode::find_encoding (recurses: max depth 1, inclusive time 87µs)
11142µs91µsEncode::::BEGIN@12 Encode::BEGIN@12
11136µs45µsEncode::::BEGIN@5 Encode::BEGIN@5
11130µs95µsEncode::::BEGIN@268 Encode::BEGIN@268
11130µs40µsEncode::utf8::::BEGIN@355 Encode::utf8::BEGIN@355
11124µs24µsEncode::::CORE:match Encode::CORE:match (opcode)
11122µs206µsEncode::::BEGIN@8 Encode::BEGIN@8
71121µs21µsEncode::::CORE:subst Encode::CORE:subst (opcode)
11121µs25µsEncode::::encode_utf8 Encode::encode_utf8
11118µs40µsEncode::::BEGIN@6 Encode::BEGIN@6
11110µs10µsEncode::::BEGIN@9 Encode::BEGIN@9
0000s0sEncode::Internal::::__ANON__[:311] Encode::Internal::__ANON__[:311]
0000s0sEncode::UTF_EBCDIC::::__ANON__[:286]Encode::UTF_EBCDIC::__ANON__[:286]
0000s0sEncode::UTF_EBCDIC::::__ANON__[:298]Encode::UTF_EBCDIC::__ANON__[:298]
0000s0sEncode::::__ANON__[:167] Encode::__ANON__[:167]
0000s0sEncode::::__ANON__[:196] Encode::__ANON__[:196]
0000s0sEncode::::clone_encoding Encode::clone_encoding
0000s0sEncode::::decode Encode::decode
0000s0sEncode::::decode_utf8 Encode::decode_utf8
0000s0sEncode::::encode Encode::encode
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__[:343] Encode::utf8::__ANON__[:343]
0000s0sEncode::utf8::::__ANON__[:349] Encode::utf8::__ANON__[:349]
0000s0sEncode::utf8::::__ANON__[:365] Encode::utf8::__ANON__[:365]
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.80 2016/01/25 14:54:01 dankogai Exp $
3#
4package Encode;
5252µs253µs
# spent 45µs (36+8) within Encode::BEGIN@5 which was called: # once (36µs+8µs) by Pod::Text::BEGIN@33 at line 5
use strict;
# spent 45µs making 1 call to Encode::BEGIN@5 # spent 8µs making 1 call to strict::import
62142µs261µs
# spent 40µs (18+21) within Encode::BEGIN@6 which was called: # once (18µs+21µs) by Pod::Text::BEGIN@33 at line 6
use warnings;
# spent 40µs making 1 call to Encode::BEGIN@6 # spent 21µs making 1 call to warnings::import
7146µs124µsour $VERSION = sprintf "%d.%02d_01", q$Revision: 2.80 $ =~ /(\d+)/g;
# spent 24µs making 1 call to Encode::CORE:match
8255µs2391µs
# spent 206µs (22+185) within Encode::BEGIN@8 which was called: # once (22µs+185µs) by Pod::Text::BEGIN@33 at line 8
use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG};
# spent 206µs making 1 call to Encode::BEGIN@8 # spent 185µs making 1 call to constant::import
9287µs110µs
# spent 10µs within Encode::BEGIN@9 which was called: # once (10µs+0s) by Pod::Text::BEGIN@33 at line 9
use XSLoader ();
# spent 10µs making 1 call to Encode::BEGIN@9
101518µs1670µsXSLoader::load( __PACKAGE__, $VERSION );
# spent 670µs making 1 call to XSLoader::load
11
123327µs3141µs
# spent 91µs (42+50) within Encode::BEGIN@12 which was called: # once (42µs+50µs) by Pod::Text::BEGIN@33 at line 12
use Exporter 5.57 'import';
# spent 91µs making 1 call to Encode::BEGIN@12 # spent 25µs making 1 call to Exporter::import # spent 24µs making 1 call to UNIVERSAL::VERSION
13
14# Public, encouraged API is exported by default
15
1616µsour @EXPORT = qw(
17 decode decode_utf8 encode encode_utf8 str2bytes bytes2str
18 encodings find_encoding clone_encoding
19);
2014µsour @FB_FLAGS = qw(
21 DIE_ON_ERR WARN_ON_ERR RETURN_ON_ERR LEAVE_SRC
22 PERLQQ HTMLCREF XMLCREF STOP_AT_PARTIAL
23);
2414µsour @FB_CONSTS = qw(
25 FB_DEFAULT FB_CROAK FB_QUIET FB_WARN
26 FB_PERLQQ FB_HTMLCREF FB_XMLCREF
27);
2818µsour @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
36119µsour %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
4512µsour $ON_EBCDIC = ( ord("A") == 193 );
46
4722.89ms26.54ms
# spent 6.39ms (3.80+2.59) within Encode::BEGIN@47 which was called: # once (3.80ms+2.59ms) by Pod::Text::BEGIN@33 at line 47
use Encode::Alias;
# spent 6.39ms making 1 call to Encode::BEGIN@47 # spent 144µs making 1 call to Exporter::import
48
49# Make a %Encoding package variable to allow a certain amount of cheating
50our %Encoding;
51our %ExtModule;
521482µsrequire 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.
5612µseval {
5718µs local $SIG{__DIE__};
5814µs local $SIG{__WARN__};
59114µs local @INC = @INC;
6014µs pop @INC if $INC[-1] eq '.';
611176µs require Encode::ConfigLocal;
62};
63
64sub encodings {
65 my %enc;
66 my $arg = $_[1] || '';
67 if ( $arg eq ":all" ) {
68 %enc = ( %Encoding, %ExtModule );
69 }
70 else {
71 %enc = %Encoding;
72 for my $mod ( map { m/::/ ? $_ : "Encode::$_" } @_ ) {
73 DEBUG and warn $mod;
74 for my $enc ( keys %ExtModule ) {
75 $ExtModule{$enc} eq $mod and $enc{$enc} = $mod;
76 }
77 }
78 }
79 return sort { lc $a cmp lc $b }
80 grep { !/^(?:Internal|Unicode|Guess)$/o } keys %enc;
81}
82
83sub perlio_ok {
84 my $obj = ref( $_[0] ) ? $_[0] : find_encoding( $_[0] );
85 $obj->can("perlio_ok") and return $obj->perlio_ok();
86 return 0; # safety net
87}
88
89
# spent 127µs within Encode::define_encoding which was called 5 times, avg 25µs/call: # 5 times (127µs+0s) by XSLoader::load at line 114 of XSLoader.pm, avg 25µs/call
sub define_encoding {
90510µs my $obj = shift;
9159µs my $name = shift;
92515µs $Encoding{$name} = $obj;
93513µs my $lc = lc($name);
9459µs define_alias( $lc => $obj ) unless $lc eq $name;
95518µs while (@_) {
96 my $alias = shift;
97 define_alias( $alias, $obj );
98 }
99546µs return $obj;
100}
101
102
# spent 1.33ms (169µs+1.16) within Encode::getEncoding which was called 7 times, avg 190µs/call: # 7 times (169µs+1.16ms) by Encode::find_encoding at line 130, avg 190µs/call
sub getEncoding {
103716µs my ( $class, $name, $skip_external ) = @_;
104
105776µs721µs $name =~ s/\s+//g; # https://rt.cpan.org/Ticket/Display.html?id=65796
# spent 21µs making 7 calls to Encode::CORE:subst, avg 3µs/call
106
107712µs ref($name) && $name->can('renew') and return $name;
108754µs exists $Encoding{$name} and return $Encoding{$name};
10927µs my $lc = lc $name;
11024µs exists $Encoding{$lc} and return $Encoding{$lc};
111
112215µs21.18ms my $oc = $class->find_alias($name);
# spent 1.18ms making 2 calls to Encode::Alias::find_alias, avg 591µs/call
113212µs defined($oc) and return $oc;
114 $lc ne $name and $oc = $class->find_alias($lc);
115 defined($oc) and return $oc;
116
117 unless ($skip_external) {
118 if ( my $mod = $ExtModule{$name} || $ExtModule{$lc} ) {
119 $mod =~ s,::,/,g;
120 $mod .= '.pm';
121 eval { require $mod; };
122 exists $Encoding{$name} and return $Encoding{$name};
123 }
124 }
125 return;
126}
127
128
# spent 1.41ms (124µs+1.29) within Encode::find_encoding which was called 7 times, avg 201µs/call: # 2 times (46µs+-46µs) by Encode::Alias::find_alias at line 46 of Encode/Alias.pm, avg 0s/call # once (11µs+954µs) by Mail::SpamAssassin::Message::Node::BEGIN@49 at line 52 of Mail/SpamAssassin/Message/Node.pm # once (15µs+309µs) by Mail::SpamAssassin::Message::Node::BEGIN@49 at line 51 of Mail/SpamAssassin/Message/Node.pm # once (21µs+25µs) by Net::DNS::Domain::BEGIN@44 at line 46 of Net/DNS/Domain.pm # once (18µs+27µs) by Net::DNS::RR::BEGIN@42 at line 59 of Net/DNS/Domain.pm # once (12µs+16µs) by Net::DNS::RR::BEGIN@42 at line 60 of Net/DNS/Domain.pm
sub find_encoding($;$) {
129718µs my ( $name, $skip_external ) = @_;
1307101µs71.33ms return __PACKAGE__->getEncoding( $name, $skip_external );
# spent 1.37ms making 7 calls to Encode::getEncoding, avg 196µs/call, recursion: max depth 1, sum of overlapping time 41µs
131}
132
133sub resolve_alias($) {
134 my $obj = find_encoding(shift);
135 defined $obj and return $obj->name;
136 return;
137}
138
139sub clone_encoding($) {
140 my $obj = find_encoding(shift);
141 ref $obj or return;
142 eval { require Storable };
143 $@ and return;
144 return Storable::dclone($obj);
145}
146
147sub encode($$;$) {
148 my ( $name, $string, $check ) = @_;
149 return undef unless defined $string;
150 $string .= ''; # stringify;
151 $check ||= 0;
152 unless ( defined $name ) {
153 require Carp;
154 Carp::croak("Encoding name should not be undef");
155 }
156 my $enc = find_encoding($name);
157 unless ( defined $enc ) {
158 require Carp;
159 Carp::croak("Unknown encoding '$name'");
160 }
161 # For Unicode, warnings need to be caught and re-issued at this level
162 # so that callers can disable utf8 warnings lexically.
163 my $octets;
164 if ( ref($enc) eq 'Encode::Unicode' ) {
165 my $warn = '';
166 {
167 local $SIG{__WARN__} = sub { $warn = shift };
168 $octets = $enc->encode( $string, $check );
169 }
170 warnings::warnif('utf8', $warn) if length $warn;
171 }
172 else {
173 $octets = $enc->encode( $string, $check );
174 }
175 $_[1] = $string if $check and !ref $check and !( $check & LEAVE_SRC() );
176 return $octets;
177}
17819µs*str2bytes = \&encode;
179
180sub decode($$;$) {
181 my ( $name, $octets, $check ) = @_;
182 return undef unless defined $octets;
183 $octets .= '';
184 $check ||= 0;
185 my $enc = find_encoding($name);
186 unless ( defined $enc ) {
187 require Carp;
188 Carp::croak("Unknown encoding '$name'");
189 }
190 # For Unicode, warnings need to be caught and re-issued at this level
191 # so that callers can disable utf8 warnings lexically.
192 my $string;
193 if ( ref($enc) eq 'Encode::Unicode' ) {
194 my $warn = '';
195 {
196 local $SIG{__WARN__} = sub { $warn = shift };
197 $string = $enc->decode( $octets, $check );
198 }
199 warnings::warnif('utf8', $warn) if length $warn;
200 }
201 else {
202 $string = $enc->decode( $octets, $check );
203 }
204 $_[1] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() );
205 return $string;
206}
20713µs*bytes2str = \&decode;
208
209sub from_to($$$;$) {
210 my ( $string, $from, $to, $check ) = @_;
211 return undef unless defined $string;
212 $check ||= 0;
213 my $f = find_encoding($from);
214 unless ( defined $f ) {
215 require Carp;
216 Carp::croak("Unknown encoding '$from'");
217 }
218 my $t = find_encoding($to);
219 unless ( defined $t ) {
220 require Carp;
221 Carp::croak("Unknown encoding '$to'");
222 }
223 my $uni = $f->decode($string);
224 $_[0] = $string = $t->encode( $uni, $check );
225 return undef if ( $check && length($uni) );
226 return defined( $_[0] ) ? length($string) : undef;
227}
228
229
# spent 25µs (21+4) within Encode::encode_utf8 which was called: # once (21µs+4µs) by Net::DNS::Domain::BEGIN@49 at line 50 of Net/DNS/Domain.pm
sub encode_utf8($) {
23013µs my ($str) = @_;
231115µs14µs utf8::encode($str);
# spent 4µs making 1 call to utf8::encode
23219µs return $str;
233}
234
23512µsmy $utf8enc;
236
237sub decode_utf8($;$) {
238 my ( $octets, $check ) = @_;
239 return undef unless defined $octets;
240 $octets .= '';
241 $check ||= 0;
242 $utf8enc ||= find_encoding('utf8');
243 my $string = $utf8enc->decode( $octets, $check );
244 $_[0] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() );
245 return $string;
246}
247
248# sub decode_utf8($;$) {
249# my ( $str, $check ) = @_;
250# return $str if is_utf8($str);
251# if ($check) {
252# return decode( "utf8", $str, $check );
253# }
254# else {
255# return decode( "utf8", $str );
256# return $str;
257# }
258# }
259
260110µs11.46mspredefine_encodings(1);
# spent 1.46ms making 1 call to Encode::predefine_encodings
261
262#
263# This is to restore %Encoding if really needed;
264#
265
266
# spent 1.46ms (1.34+126µs) within Encode::predefine_encodings which was called: # once (1.34ms+126µs) by Pod::Text::BEGIN@33 at line 260
sub predefine_encodings {
2671301µs require Encode::Encoding;
26821.13ms2159µs
# spent 95µs (30+64) within Encode::BEGIN@268 which was called: # once (30µs+64µs) by Pod::Text::BEGIN@33 at line 268
no warnings 'redefine';
# spent 95µs making 1 call to Encode::BEGIN@268 # spent 64µs making 1 call to warnings::unimport
26912µs my $use_xs = shift;
27014µs if ($ON_EBCDIC) {
271
272 # was in Encode::UTF_EBCDIC
273 package Encode::UTF_EBCDIC;
274 push @Encode::UTF_EBCDIC::ISA, 'Encode::Encoding';
275 *decode = sub {
276 my ( undef, $str, $chk ) = @_;
277 my $res = '';
278 for ( my $i = 0 ; $i < length($str) ; $i++ ) {
279 $res .=
280 chr(
281 utf8::unicode_to_native( ord( substr( $str, $i, 1 ) ) )
282 );
283 }
284 $_[1] = '' if $chk;
285 return $res;
286 };
287 *encode = sub {
288 my ( undef, $str, $chk ) = @_;
289 my $res = '';
290 for ( my $i = 0 ; $i < length($str) ; $i++ ) {
291 $res .=
292 chr(
293 utf8::native_to_unicode( ord( substr( $str, $i, 1 ) ) )
294 );
295 }
296 $_[1] = '' if $chk;
297 return $res;
298 };
299 $Encode::Encoding{Unicode} =
300 bless { Name => "UTF_EBCDIC" } => "Encode::UTF_EBCDIC";
301 }
302 else {
303
304 package Encode::Internal;
305120µs push @Encode::Internal::ISA, 'Encode::Encoding';
306 *decode = sub {
307 my ( undef, $str, $chk ) = @_;
308 utf8::upgrade($str);
309 $_[1] = '' if $chk;
310 return $str;
311112µs };
31213µs *encode = \&decode;
313 $Encode::Encoding{Unicode} =
31417µs bless { Name => "Internal" } => "Encode::Internal";
315 }
316 {
317 # https://rt.cpan.org/Public/Bug/Display.html?id=103253
318 package Encode::XS;
31918µs push @Encode::XS::ISA, 'Encode::Encoding';
320 }
321 {
322
323 # was in Encode::utf8
324215µs package Encode::utf8;
32518µs push @Encode::utf8::ISA, 'Encode::Encoding';
326
327 #
32814µs if ($use_xs) {
329 Encode::DEBUG and warn __PACKAGE__, " XS on";
33014µs *decode = \&decode_xs;
33113µs *encode = \&encode_xs;
332 }
333 else {
334 Encode::DEBUG and warn __PACKAGE__, " XS off";
335 *decode = sub {
336 my ( undef, $octets, $chk ) = @_;
337 my $str = Encode::decode_utf8($octets);
338 if ( defined $str ) {
339 $_[1] = '' if $chk;
340 return $str;
341 }
342 return undef;
343 };
344 *encode = sub {
345 my ( undef, $string, $chk ) = @_;
346 my $octets = Encode::encode_utf8($string);
347 $_[1] = '' if $chk;
348 return $octets;
349 };
350 }
351 *cat_decode = sub { # ($obj, $dst, $src, $pos, $trm, $chk)
352 # currently ignores $chk
353 my ( undef, undef, undef, $pos, $trm ) = @_;
354 my ( $rdst, $rsrc, $rpos ) = \@_[ 1, 2, 3 ];
3552390µs250µs
# spent 40µs (30+10) within Encode::utf8::BEGIN@355 which was called: # once (30µs+10µs) by Pod::Text::BEGIN@33 at line 355
use bytes;
# spent 40µs making 1 call to Encode::utf8::BEGIN@355 # spent 10µs making 1 call to bytes::import
356 if ( ( my $npos = index( $$rsrc, $trm, $pos ) ) >= 0 ) {
357 $$rdst .=
358 substr( $$rsrc, $pos, $npos - $pos + length($trm) );
359 $$rpos = $npos + length($trm);
360 return 1;
361 }
362 $$rdst .= substr( $$rsrc, $pos );
363 $$rpos = length($$rsrc);
364 return '';
365110µs };
366 $Encode::Encoding{utf8} =
36716µs bless { Name => "utf8" } => "Encode::utf8";
36817µs $Encode::Encoding{"utf-8-strict"} =
369 bless { Name => "utf-8-strict", strict_utf8 => 1 }
370 => "Encode::utf8";
371 }
372}
373
374166µs1;
375
376__END__
 
# spent 24µs within Encode::CORE:match which was called: # once (24µs+0s) by Pod::Text::BEGIN@33 at line 7
sub Encode::CORE:match; # opcode
# spent 21µs within Encode::CORE:subst which was called 7 times, avg 3µs/call: # 7 times (21µs+0s) by Encode::getEncoding at line 105, avg 3µs/call
sub Encode::CORE:subst; # opcode
# spent 9.69ms within Encode::utf8::encode_xs which was called 1039 times, avg 9µs/call: # 1039 times (9.69ms+0s) by Net::DNS::Domain::_encode_utf8 at line 312 of Net/DNS/Domain.pm, avg 9µs/call
sub Encode::utf8::encode_xs; # xsub