← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mentat.storage.mongo.pl
  Run on Tue Jun 24 09:58:41 2014
Reported on Tue Jun 24 09:59:13 2014

Filename/usr/lib/perl/5.14/Encode.pm
StatementsExecuted 78 statements in 2.44ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.41ms1.97msEncode::::BEGIN@48 Encode::BEGIN@48
111479µs510µsEncode::::predefine_encodings Encode::predefine_encodings
41112µs12µsEncode::::define_encoding Encode::define_encoding
11112µs15µsEncode::::BEGIN@5 Encode::BEGIN@5
11111µs14µsEncode::utf8::::BEGIN@323 Encode::utf8::BEGIN@323
1119µs20µsEncode::::BEGIN@240 Encode::BEGIN@240
1116µs11µsEncode::::BEGIN@6 Encode::BEGIN@6
1116µs46µsEncode::::BEGIN@13 Encode::BEGIN@13
1114µs4µsEncode::::BEGIN@9 Encode::BEGIN@9
1114µs4µsEncode::::CORE:match Encode::CORE:match (opcode)
0000s0sEncode::Internal::::__ANON__[:283] Encode::Internal::__ANON__[:283]
0000s0sEncode::UTF_EBCDIC::::__ANON__[:258]Encode::UTF_EBCDIC::__ANON__[:258]
0000s0sEncode::UTF_EBCDIC::::__ANON__[:270]Encode::UTF_EBCDIC::__ANON__[:270]
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::::find_encoding Encode::find_encoding
0000s0sEncode::::from_to Encode::from_to
0000s0sEncode::::getEncoding Encode::getEncoding
0000s0sEncode::::perlio_ok Encode::perlio_ok
0000s0sEncode::::resolve_alias Encode::resolve_alias
0000s0sEncode::utf8::::__ANON__[:311] Encode::utf8::__ANON__[:311]
0000s0sEncode::utf8::::__ANON__[:317] Encode::utf8::__ANON__[:317]
0000s0sEncode::utf8::::__ANON__[:333] Encode::utf8::__ANON__[:333]
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.42 2010/12/31 22:48:10 dankogai Exp $
3#
4package Encode;
5221µs218µs
# spent 15µs (12+3) within Encode::BEGIN@5 which was called: # once (12µs+3µs) by MongoDB::MongoClient::BEGIN@34 at line 5
use strict;
# spent 15µs making 1 call to Encode::BEGIN@5 # spent 3µs making 1 call to strict::import
6254µs216µs
# spent 11µs (6+5) within Encode::BEGIN@6 which was called: # once (6µs+5µs) by MongoDB::MongoClient::BEGIN@34 at line 6
use warnings;
# spent 11µs making 1 call to Encode::BEGIN@6 # spent 5µs making 1 call to warnings::import
7111µs14µsour $VERSION = sprintf "%d.%02d_01", q$Revision: 2.42 $ =~ /(\d+)/g;
# spent 4µs making 1 call to Encode::CORE:match
8sub DEBUG () { 0 }
9234µs14µs
# spent 4µs within Encode::BEGIN@9 which was called: # once (4µs+0s) by MongoDB::MongoClient::BEGIN@34 at line 9
use XSLoader ();
# spent 4µs making 1 call to Encode::BEGIN@9
101180µs1207µsXSLoader::load( __PACKAGE__, $VERSION );
# spent 207µs making 1 call to XSLoader::load
11
121700nsrequire Exporter;
132121µs287µs
# spent 46µs (6+40) within Encode::BEGIN@13 which was called: # once (6µs+40µs) by MongoDB::MongoClient::BEGIN@34 at line 13
use base qw/Exporter/;
# spent 46µs making 1 call to Encode::BEGIN@13 # spent 40µ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);
251900nsour @FB_CONSTS = qw(
26 FB_DEFAULT FB_CROAK FB_QUIET FB_WARN
27 FB_PERLQQ FB_HTMLCREF FB_XMLCREF
28);
2916µ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
37111µ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
461400nsour $ON_EBCDIC = ( ord("A") == 193 );
47
4821.11ms22.01ms
# spent 1.97ms (1.41+554µs) within Encode::BEGIN@48 which was called: # once (1.41ms+554µs) by MongoDB::MongoClient::BEGIN@34 at line 48
use Encode::Alias;
# spent 1.97ms making 1 call to Encode::BEGIN@48 # spent 38µs making 1 call to Exporter::import
49
50# Make a %Encoding package variable to allow a certain amount of cheating
511200nsour %Encoding;
521100nsour %ExtModule;
531116µ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__};
591800ns local $SIG{__WARN__};
60136µs require Encode::ConfigLocal;
61};
62
63sub encodings {
64 my $class = shift;
65 my %enc;
66 if ( @_ and $_[0] eq ":all" ) {
67 %enc = ( %Encoding, %ExtModule );
68 }
69 else {
70 %enc = %Encoding;
71 for my $mod ( map { m/::/o ? $_ : "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 12µs within Encode::define_encoding which was called 4 times, avg 3µs/call: # 4 times (12µs+0s) by XSLoader::load at line 95 of XSLoader.pm, avg 3µs/call
sub define_encoding {
892818µs my $obj = shift;
90 my $name = shift;
91 $Encoding{$name} = $obj;
92 my $lc = lc($name);
93 define_alias( $lc => $obj ) unless $lc eq $name;
94 while (@_) {
95 my $alias = shift;
96 define_alias( $alias, $obj );
97 }
98 return $obj;
99}
100
101sub getEncoding {
102 my ( $class, $name, $skip_external ) = @_;
103
104 ref($name) && $name->can('renew') and return $name;
105 exists $Encoding{$name} and return $Encoding{$name};
106 my $lc = lc $name;
107 exists $Encoding{$lc} and return $Encoding{$lc};
108
109 my $oc = $class->find_alias($name);
110 defined($oc) and return $oc;
111 $lc ne $name and $oc = $class->find_alias($lc);
112 defined($oc) and return $oc;
113
114 unless ($skip_external) {
115 if ( my $mod = $ExtModule{$name} || $ExtModule{$lc} ) {
116 $mod =~ s,::,/,g;
117 $mod .= '.pm';
118 eval { require $mod; };
119 exists $Encoding{$name} and return $Encoding{$name};
120 }
121 }
122 return;
123}
124
125sub find_encoding($;$) {
126 my ( $name, $skip_external ) = @_;
127 return __PACKAGE__->getEncoding( $name, $skip_external );
128}
129
130sub resolve_alias($) {
131 my $obj = find_encoding(shift);
132 defined $obj and return $obj->name;
133 return;
134}
135
136sub clone_encoding($) {
137 my $obj = find_encoding(shift);
138 ref $obj or return;
139 eval { require Storable };
140 $@ and return;
141 return Storable::dclone($obj);
142}
143
144sub encode($$;$) {
145 my ( $name, $string, $check ) = @_;
146 return undef unless defined $string;
147 $string .= '' if ref $string; # stringify;
148 $check ||= 0;
149 unless ( defined $name ) {
150 require Carp;
151 Carp::croak("Encoding name should not be undef");
152 }
153 my $enc = find_encoding($name);
154 unless ( defined $enc ) {
155 require Carp;
156 Carp::croak("Unknown encoding '$name'");
157 }
158 my $octets = $enc->encode( $string, $check );
159 $_[1] = $string if $check and !ref $check and !( $check & LEAVE_SRC() );
160 return $octets;
161}
16212µs*str2bytes = \&encode;
163
164sub decode($$;$) {
165 my ( $name, $octets, $check ) = @_;
166 return undef unless defined $octets;
167 $octets .= '' if ref $octets;
168 $check ||= 0;
169 my $enc = find_encoding($name);
170 unless ( defined $enc ) {
171 require Carp;
172 Carp::croak("Unknown encoding '$name'");
173 }
174 my $string = $enc->decode( $octets, $check );
175 $_[1] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() );
176 return $string;
177}
1781500ns*bytes2str = \&decode;
179
180sub from_to($$$;$) {
181 my ( $string, $from, $to, $check ) = @_;
182 return undef unless defined $string;
183 $check ||= 0;
184 my $f = find_encoding($from);
185 unless ( defined $f ) {
186 require Carp;
187 Carp::croak("Unknown encoding '$from'");
188 }
189 my $t = find_encoding($to);
190 unless ( defined $t ) {
191 require Carp;
192 Carp::croak("Unknown encoding '$to'");
193 }
194 my $uni = $f->decode($string);
195 $_[0] = $string = $t->encode( $uni, $check );
196 return undef if ( $check && length($uni) );
197 return defined( $_[0] ) ? length($string) : undef;
198}
199
200sub encode_utf8($) {
201 my ($str) = @_;
202 utf8::encode($str);
203 return $str;
204}
205
2061100nsmy $utf8enc;
207
208sub decode_utf8($;$) {
209 my ( $octets, $check ) = @_;
210 return $octets if is_utf8($octets);
211 return undef unless defined $octets;
212 $octets .= '' if ref $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
23212µs1510µspredefine_encodings(1);
# spent 510µs making 1 call to Encode::predefine_encodings
233
234#
235# This is to restore %Encoding if really needed;
236#
237
238
# spent 510µs (479+31) within Encode::predefine_encodings which was called: # once (479µs+31µs) by MongoDB::MongoClient::BEGIN@34 at line 232
sub predefine_encodings {
23915116µs require Encode::Encoding;
2402448µs231µs
# spent 20µs (9+11) within Encode::BEGIN@240 which was called: # once (9µs+11µs) by MongoDB::MongoClient::BEGIN@34 at line 240
no warnings 'redefine';
# spent 20µs making 1 call to Encode::BEGIN@240 # spent 11µs making 1 call to warnings::unimport
241 my $use_xs = shift;
242 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 ( $obj, $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 ( $obj, $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 push @Encode::Internal::ISA, 'Encode::Encoding';
278 *decode = sub {
279 my ( $obj, $str, $chk ) = @_;
280 utf8::upgrade($str);
281 $_[1] = '' if $chk;
282 return $str;
283 };
284 *encode = \&decode;
285 $Encode::Encoding{Unicode} =
286 bless { Name => "Internal" } => "Encode::Internal";
287 }
288
289 {
290
291 # was in Encode::utf8
292 package Encode::utf8;
293 push @Encode::utf8::ISA, 'Encode::Encoding';
294
295 #
296 if ($use_xs) {
297 Encode::DEBUG and warn __PACKAGE__, " XS on";
298 *decode = \&decode_xs;
299 *encode = \&encode_xs;
300 }
301 else {
302 Encode::DEBUG and warn __PACKAGE__, " XS off";
303 *decode = sub {
304 my ( $obj, $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 ( $obj, $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 ( $obj, undef, undef, $pos, $trm ) = @_;
322 my ( $rdst, $rsrc, $rpos ) = \@_[ 1, 2, 3 ];
3232131µs218µs
# spent 14µs (11+3) within Encode::utf8::BEGIN@323 which was called: # once (11µs+3µs) by MongoDB::MongoClient::BEGIN@34 at line 323
use bytes;
# spent 14µs making 1 call to Encode::utf8::BEGIN@323 # spent 3µ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 };
334 $Encode::Encoding{utf8} =
335 bless { Name => "utf8" } => "Encode::utf8";
336 $Encode::Encoding{"utf-8-strict"} =
337 bless { Name => "utf-8-strict", strict_utf8 => 1 } =>
338 "Encode::utf8";
339 }
340}
341
342115µs1;
343
344__END__
 
# spent 4µs within Encode::CORE:match which was called: # once (4µs+0s) by MongoDB::MongoClient::BEGIN@34 at line 7
sub Encode::CORE:match; # opcode