← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:10 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/5.18.2/darwin-2level/Encode.pm
StatementsExecuted 96 statements in 2.65ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.41ms2.09msEncode::::BEGIN@48 Encode::BEGIN@48
111786┬Ás900┬ÁsEncode::::BEGIN@13 Encode::BEGIN@13
111445┬Ás482┬ÁsEncode::::predefine_encodings Encode::predefine_encodings
111186┬Ás188┬ÁsEncode::utf8::::BEGIN@325 Encode::utf8::BEGIN@325
1111167┬Ás180┬ÁsEncode::utf8::::decode_xs Encode::utf8::decode_xs (xsub)
21123┬Ás97┬ÁsEncode::::getEncoding Encode::getEncoding (recurses: max depth 1, inclusive time 8┬Ás)
41117┬Ás17┬ÁsEncode::::define_encoding Encode::define_encoding
22214┬Ás104┬ÁsEncode::::find_encoding Encode::find_encoding (recurses: max depth 1, inclusive time 15┬Ás)
11112┬Ás28┬ÁsEncode::::BEGIN@5 Encode::BEGIN@5
1119┬Ás19┬ÁsEncode::::BEGIN@242 Encode::BEGIN@242
2228┬Ás8┬ÁsEncode::::PERLQQ Encode::PERLQQ (xsub)
1118┬Ás15┬ÁsEncode::::BEGIN@6 Encode::BEGIN@6
1118┬Ás47┬ÁsEncode::::BEGIN@8 Encode::BEGIN@8
1116┬Ás6┬ÁsEncode::::BEGIN@9 Encode::BEGIN@9
1114┬Ás4┬ÁsEncode::::CORE:match Encode::CORE:match (opcode)
2112┬Ás2┬ÁsEncode::::CORE:subst Encode::CORE:subst (opcode)
111700ns700nsEncode::::STOP_AT_PARTIAL Encode::STOP_AT_PARTIAL (xsub)
111700ns700nsEncode::::WARN_ON_ERR Encode::WARN_ON_ERR (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::::decode Encode::decode
0000s0sEncode::::decode_utf8 Encode::decode_utf8
0000s0sEncode::::encode Encode::encode
0000s0sEncode::::encode_utf8 Encode::encode_utf8
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.49 2013/03/05 03:13:47 dankogai Exp dankogai $
3#
4package Encode;
5220┬Ás243┬Ás
# spent 28┬Ás (12+16) within Encode::BEGIN@5 which was called: # once (12┬Ás+16┬Ás) by Pod::Text::BEGIN@32 at line 5
use strict;
# spent 28┬Ás making 1 call to Encode::BEGIN@5 # spent 16┬Ás making 1 call to strict::import
6245┬Ás221┬Ás
# spent 15┬Ás (8+7) within Encode::BEGIN@6 which was called: # once (8┬Ás+7┬Ás) by Pod::Text::BEGIN@32 at line 6
use warnings;
# spent 15┬Ás making 1 call to Encode::BEGIN@6 # spent 7┬Ás making 1 call to warnings::import
7111┬Ás14┬Ásour $VERSION = sprintf "%d.%02d", q$Revision: 2.49 $ =~ /(\d+)/g;
# spent 4┬Ás making 1 call to Encode::CORE:match
8224┬Ás286┬Ás
# spent 47┬Ás (8+39) within Encode::BEGIN@8 which was called: # once (8┬Ás+39┬Ás) by Pod::Text::BEGIN@32 at line 8
use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG};
# spent 47┬Ás making 1 call to Encode::BEGIN@8 # spent 39┬Ás making 1 call to constant::import
9230┬Ás16┬Ás
# spent 6┬Ás within Encode::BEGIN@9 which was called: # once (6┬Ás+0s) by Pod::Text::BEGIN@32 at line 9
use XSLoader ();
# spent 6┬Ás making 1 call to Encode::BEGIN@9
101323┬Ás1355┬ÁsXSLoader::load( __PACKAGE__, $VERSION );
# spent 355┬Ás making 1 call to XSLoader::load
11
121300nsrequire Exporter;
132174┬Ás2962┬Ás
# spent 900┬Ás (786+113) within Encode::BEGIN@13 which was called: # once (786┬Ás+113┬Ás) by Pod::Text::BEGIN@32 at line 13
use base qw/Exporter/;
# spent 900┬Ás making 1 call to Encode::BEGIN@13 # spent 63┬Á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);
2511┬Ásour @FB_CONSTS = qw(
26 FB_DEFAULT FB_CROAK FB_QUIET FB_WARN
27 FB_PERLQQ FB_HTMLCREF FB_XMLCREF
28);
2914┬Á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
37112┬Á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
461300nsour $ON_EBCDIC = ( ord("A") == 193 );
47
482994┬Ás22.12ms
# spent 2.09ms (1.41+676┬Ás) within Encode::BEGIN@48 which was called: # once (1.41ms+676┬Ás) by Pod::Text::BEGIN@32 at line 48
use Encode::Alias;
# spent 2.09ms making 1 call to Encode::BEGIN@48 # spent 28┬Ás making 1 call to Exporter::import
49
50# Make a %Encoding package variable to allow a certain amount of cheating
511100nsour %Encoding;
5210sour %ExtModule;
53195┬Á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.
571200nseval {
5812┬Ás local $SIG{__DIE__};
591500ns local $SIG{__WARN__};
60136┬Á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 17┬Ás within Encode::define_encoding which was called 4 times, avg 4┬Ás/call: # 4 times (17┬Ás+0s) by XSLoader::load at line 95 of XSLoader.pm, avg 4┬Ás/call
sub define_encoding {
8941┬Ás my $obj = shift;
904600ns my $name = shift;
9142┬Ás $Encoding{$name} = $obj;
9244┬Ás my $lc = lc($name);
934600ns define_alias( $lc => $obj ) unless $lc eq $name;
9441┬Ás while (@_) {
95 my $alias = shift;
96 define_alias( $alias, $obj );
97 }
98410┬Ás return $obj;
99}
100
101
# spent 97┬Ás (23+74) within Encode::getEncoding which was called 2 times, avg 48┬Ás/call: # 2 times (23┬Ás+74┬Ás) by Encode::find_encoding at line 129, avg 48┬Ás/call
sub getEncoding {
10221┬Ás my ( $class, $name, $skip_external ) = @_;
103
10429┬Ás22┬Ás $name =~ s/\s+//g; # https://rt.cpan.org/Ticket/Display.html?id=65796
# spent 2┬Ás making 2 calls to Encode::CORE:subst, avg 800ns/call
105
1062400ns ref($name) && $name->can('renew') and return $name;
10726┬Ás exists $Encoding{$name} and return $Encoding{$name};
10811┬Ás my $lc = lc $name;
1091400ns exists $Encoding{$lc} and return $Encoding{$lc};
110
11113┬Ás180┬Ás my $oc = $class->find_alias($name);
# spent 80┬Ás making 1 call to Encode::Alias::find_alias
11212┬Á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 104┬Ás (14+89) within Encode::find_encoding which was called 2 times, avg 52┬Ás/call: # once (7┬Ás+97┬Ás) by Path::Tiny::CORE:open at line 816 of Path/Tiny.pm # once (8┬Ás+-8┬Ás) by Encode::Alias::find_alias at line 46 of Encode/Alias.pm
sub find_encoding($;$) {
12821┬Ás my ( $name, $skip_external ) = @_;
129211┬Ás297┬Ás return __PACKAGE__->getEncoding( $name, $skip_external );
# spent 104┬Ás making 2 calls to Encode::getEncoding, avg 52┬Ás/call, recursion: max depth 1, sum of overlapping time 8┬Á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
146sub encode($$;$) {
147 my ( $name, $string, $check ) = @_;
148 return undef unless defined $string;
149 $string .= ''; # stringify;
150 $check ||= 0;
151 unless ( defined $name ) {
152 require Carp;
153 Carp::croak("Encoding name should not be undef");
154 }
155 my $enc = find_encoding($name);
156 unless ( defined $enc ) {
157 require Carp;
158 Carp::croak("Unknown encoding '$name'");
159 }
160 my $octets = $enc->encode( $string, $check );
161 $_[1] = $string if $check and !ref $check and !( $check & LEAVE_SRC() );
162 return $octets;
163}
1641900ns*str2bytes = \&encode;
165
166sub decode($$;$) {
167 my ( $name, $octets, $check ) = @_;
168 return undef unless defined $octets;
169 $octets .= '';
170 $check ||= 0;
171 my $enc = find_encoding($name);
172 unless ( defined $enc ) {
173 require Carp;
174 Carp::croak("Unknown encoding '$name'");
175 }
176 my $string = $enc->decode( $octets, $check );
177 $_[1] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() );
178 return $string;
179}
1801200ns*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
202sub encode_utf8($) {
203 my ($str) = @_;
204 utf8::encode($str);
205 return $str;
206}
207
2081100nsmy $utf8enc;
209
210sub decode_utf8($;$) {
211 my ( $octets, $check ) = @_;
212 return $octets if is_utf8($octets);
213 return undef unless defined $octets;
214 $octets .= '' if ref $octets;
215 $check ||= 0;
216 $utf8enc ||= find_encoding('utf8');
217 my $string = $utf8enc->decode( $octets, $check );
218 $_[0] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() );
219 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
23412┬Ás1482┬Áspredefine_encodings(1);
# spent 482┬Ás making 1 call to Encode::predefine_encodings
235
236#
237# This is to restore %Encoding if really needed;
238#
239
240
# spent 482┬Ás (445+37) within Encode::predefine_encodings which was called: # once (445┬Ás+37┬Ás) by Pod::Text::BEGIN@32 at line 234
sub predefine_encodings {
241156┬Ás require Encode::Encoding;
2422432┬Ás228┬Ás
# spent 19┬Ás (9+10) within Encode::BEGIN@242 which was called: # once (9┬Ás+10┬Ás) by Pod::Text::BEGIN@32 at line 242
no warnings 'redefine';
# spent 19┬Ás making 1 call to Encode::BEGIN@242 # spent 10┬Ás making 1 call to warnings::unimport
2431300ns my $use_xs = shift;
2441400ns 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;
27915┬Á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;
28512┬Ás };
2861300ns *encode = \&decode;
28712┬Ás $Encode::Encoding{Unicode} =
288 bless { Name => "Internal" } => "Encode::Internal";
289 }
290
291 {
292
293 # was in Encode::utf8
29414┬Ás package Encode::utf8;
29512┬Ás push @Encode::utf8::ISA, 'Encode::Encoding';
296
297 #
2981100ns if ($use_xs) {
299 Encode::DEBUG and warn __PACKAGE__, " XS on";
3001400ns *decode = \&decode_xs;
3011200ns *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 ];
3252284┬Ás2190┬Ás
# spent 188┬Ás (186+2) within Encode::utf8::BEGIN@325 which was called: # once (186┬Ás+2┬Ás) by Pod::Text::BEGIN@32 at line 325
use bytes;
# spent 188┬Ás making 1 call to Encode::utf8::BEGIN@325 # spent 2┬Á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 '';
33512┬Ás };
33611┬Ás $Encode::Encoding{utf8} =
337 bless { Name => "utf8" } => "Encode::utf8";
33811┬Á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 4┬Ás within Encode::CORE:match which was called: # once (4┬Ás+0s) by Pod::Text::BEGIN@32 at line 7
sub Encode::CORE:match; # opcode
# spent 2┬Ás within Encode::CORE:subst which was called 2 times, avg 800ns/call: # 2 times (2┬Ás+0s) by Encode::getEncoding at line 104, avg 800ns/call
sub Encode::CORE:subst; # opcode
# spent 8┬Ás within Encode::PERLQQ which was called 2 times, avg 4┬Ás/call: # once (7┬Ás+0s) by XSLoader::load at line 95 of XSLoader.pm # once (800ns+0s) by PerlIO::import at line 16 of PerlIO/encoding.pm
sub Encode::PERLQQ; # xsub
# spent 700ns within Encode::STOP_AT_PARTIAL which was called: # once (700ns+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 180┬Ás (167+13) within Encode::utf8::decode_xs which was called 11 times, avg 16┬Ás/call: # 11 times (167┬Ás+13┬Ás) by Path::Tiny::CORE:readline at line 997 of Path/Tiny.pm, avg 16┬Ás/call
sub Encode::utf8::decode_xs; # xsub