← 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