| Filename | /usr/share/perl5/URI/Escape.pm |
| Statements | Executed 313 statements in 1.40ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 3 | 3 | 2 | 194µs | 282µs | URI::Escape::uri_escape |
| 18 | 1 | 1 | 46µs | 46µs | URI::Escape::CORE:substcont (opcode) |
| 3 | 1 | 1 | 32µs | 32µs | URI::Escape::CORE:regcomp (opcode) |
| 1 | 1 | 1 | 28µs | 32µs | URI::Escape::BEGIN@2 |
| 1 | 1 | 1 | 18µs | 20µs | URI::Escape::uri_unescape |
| 1 | 1 | 1 | 15µs | 119µs | URI::Escape::BEGIN@142 |
| 4 | 2 | 1 | 13µs | 13µs | URI::Escape::CORE:subst (opcode) |
| 2 | 1 | 1 | 11µs | 11µs | URI::Escape::CORE:qr (opcode) |
| 1 | 1 | 1 | 10µs | 31µs | URI::Escape::BEGIN@143 |
| 1 | 1 | 1 | 6µs | 6µs | URI::Escape::BEGIN@151 |
| 0 | 0 | 0 | 0s | 0s | URI::Escape::_fail_hi |
| 0 | 0 | 0 | 0s | 0s | URI::Escape::escape_char |
| 0 | 0 | 0 | 0s | 0s | URI::Escape::uri_escape_utf8 |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package URI::Escape; | ||||
| 2 | 3 | 89µs | 2 | 36µs | # spent 32µs (28+4) within URI::Escape::BEGIN@2 which was called:
# once (28µs+4µs) by C4::Output::BEGIN@31 at line 2 # spent 32µs making 1 call to URI::Escape::BEGIN@2
# spent 4µs making 1 call to strict::import |
| 3 | |||||
| 4 | =head1 NAME | ||||
| 5 | |||||
| - - | |||||
| 142 | 3 | 40µs | 2 | 223µs | # spent 119µs (15+104) within URI::Escape::BEGIN@142 which was called:
# once (15µs+104µs) by C4::Output::BEGIN@31 at line 142 # spent 119µs making 1 call to URI::Escape::BEGIN@142
# spent 104µs making 1 call to vars::import |
| 143 | 3 | 61µs | 2 | 52µs | # spent 31µs (10+21) within URI::Escape::BEGIN@143 which was called:
# once (10µs+21µs) by C4::Output::BEGIN@31 at line 143 # spent 31µs making 1 call to URI::Escape::BEGIN@143
# spent 21µs making 1 call to vars::import |
| 144 | |||||
| 145 | 1 | 1µs | require Exporter; | ||
| 146 | 1 | 11µs | @ISA = qw(Exporter); | ||
| 147 | 1 | 900ns | @EXPORT = qw(uri_escape uri_unescape uri_escape_utf8); | ||
| 148 | 1 | 500ns | @EXPORT_OK = qw(%escapes); | ||
| 149 | 1 | 400ns | $VERSION = "3.30"; | ||
| 150 | |||||
| 151 | 3 | 502µs | 1 | 6µs | # spent 6µs within URI::Escape::BEGIN@151 which was called:
# once (6µs+0s) by C4::Output::BEGIN@31 at line 151 # spent 6µs making 1 call to URI::Escape::BEGIN@151 |
| 152 | |||||
| 153 | # Build a char->hex map | ||||
| 154 | 1 | 3µs | for (0..255) { | ||
| 155 | 256 | 357µs | $escapes{chr($_)} = sprintf("%%%02X", $_); | ||
| 156 | } | ||||
| 157 | |||||
| 158 | 1 | 300ns | my %subst; # compiled patterns | ||
| 159 | |||||
| 160 | 1 | 23µs | 2 | 11µs | my %Unsafe = ( # spent 11µs making 2 calls to URI::Escape::CORE:qr, avg 5µs/call |
| 161 | RFC2732 => qr/[^A-Za-z0-9\-_.!~*'()]/, | ||||
| 162 | RFC3986 => qr/[^A-Za-z0-9\-\._~"]/, | ||||
| 163 | ); | ||||
| 164 | |||||
| 165 | sub uri_escape | ||||
| 166 | # spent 282µs (194+88) within URI::Escape::uri_escape which was called 3 times, avg 94µs/call:
# once (160µs+58µs) by main::RUNTIME at line 648 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (27µs+29µs) by C4::Search::buildQuery at line 1508 of /usr/share/koha/lib/C4/Search.pm
# once (7µs+1µs) by C4::Search::buildQuery at line 1509 of /usr/share/koha/lib/C4/Search.pm | ||||
| 167 | 12 | 37µs | my($text, $patn) = @_; | ||
| 168 | return undef unless defined $text; | ||||
| 169 | 3 | 189µs | if (defined $patn){ | ||
| 170 | unless (exists $subst{$patn}) { | ||||
| 171 | # Because we can't compile the regex we fake it with a cached sub | ||||
| 172 | (my $tmp = $patn) =~ s,/,\\/,g; | ||||
| 173 | eval "\$subst{\$patn} = sub {\$_[0] =~ s/([$tmp])/\$escapes{\$1} || _fail_hi(\$1)/ge; }"; | ||||
| 174 | Carp::croak("uri_escape: $@") if $@; | ||||
| 175 | } | ||||
| 176 | &{$subst{$patn}}($text); | ||||
| 177 | } else { | ||||
| 178 | 17 | 55µs | 24 | 88µs | $text =~ s/($Unsafe{RFC3986})/$escapes{$1} || _fail_hi($1)/ge; # spent 46µs making 18 calls to URI::Escape::CORE:substcont, avg 3µs/call
# spent 32µs making 3 calls to URI::Escape::CORE:regcomp, avg 11µs/call
# spent 10µs making 3 calls to URI::Escape::CORE:subst, avg 3µs/call |
| 179 | } | ||||
| 180 | $text; | ||||
| 181 | } | ||||
| 182 | |||||
| 183 | sub _fail_hi { | ||||
| 184 | my $chr = shift; | ||||
| 185 | Carp::croak(sprintf "Can't escape \\x{%04X}, try uri_escape_utf8() instead", ord($chr)); | ||||
| 186 | } | ||||
| 187 | |||||
| 188 | sub uri_escape_utf8 | ||||
| 189 | { | ||||
| 190 | my $text = shift; | ||||
| 191 | if ($] < 5.008) { | ||||
| 192 | $text =~ s/([^\0-\x7F])/do {my $o = ord($1); sprintf("%c%c", 0xc0 | ($o >> 6), 0x80 | ($o & 0x3f)) }/ge; | ||||
| 193 | } | ||||
| 194 | else { | ||||
| 195 | utf8::encode($text); | ||||
| 196 | } | ||||
| 197 | |||||
| 198 | return uri_escape($text, @_); | ||||
| 199 | } | ||||
| 200 | |||||
| 201 | sub uri_unescape | ||||
| 202 | # spent 20µs (18+3) within URI::Escape::uri_unescape which was called:
# once (18µs+3µs) by main::RUNTIME at line 394 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl | ||||
| 203 | # Note from RFC1630: "Sequences which start with a percent sign | ||||
| 204 | # but are not followed by two hexadecimal characters are reserved | ||||
| 205 | # for future extension" | ||||
| 206 | 4 | 24µs | my $str = shift; | ||
| 207 | if (@_ && wantarray) { | ||||
| 208 | # not executed for the common case of a single argument | ||||
| 209 | my @str = ($str, @_); # need to copy | ||||
| 210 | foreach (@str) { | ||||
| 211 | s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; | ||||
| 212 | } | ||||
| 213 | return @str; | ||||
| 214 | } | ||||
| 215 | 1 | 3µs | $str =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg if defined $str; # spent 3µs making 1 call to URI::Escape::CORE:subst | ||
| 216 | $str; | ||||
| 217 | } | ||||
| 218 | |||||
| 219 | sub escape_char { | ||||
| 220 | return join '', @URI::Escape::escapes{$_[0] =~ /(\C)/g}; | ||||
| 221 | } | ||||
| 222 | |||||
| 223 | 1 | 11µs | 1; | ||
# spent 11µs within URI::Escape::CORE:qr which was called 2 times, avg 5µs/call:
# 2 times (11µs+0s) by C4::Output::BEGIN@31 at line 160, avg 5µs/call | |||||
# spent 32µs within URI::Escape::CORE:regcomp which was called 3 times, avg 11µs/call:
# 3 times (32µs+0s) by URI::Escape::uri_escape at line 178, avg 11µs/call | |||||
sub URI::Escape::CORE:subst; # opcode | |||||
# spent 46µs within URI::Escape::CORE:substcont which was called 18 times, avg 3µs/call:
# 18 times (46µs+0s) by URI::Escape::uri_escape at line 178, avg 3µs/call |