| Filename | /usr/share/perl5/URI/Escape.pm |
| Statements | Executed 313 statements in 1.31ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 3 | 3 | 2 | 103µs | 148µs | URI::Escape::uri_escape |
| 1 | 1 | 1 | 57µs | 85µs | URI::Escape::BEGIN@143 |
| 18 | 1 | 1 | 22µs | 22µs | URI::Escape::CORE:substcont (opcode) |
| 1 | 1 | 1 | 22µs | 26µs | URI::Escape::BEGIN@2 |
| 3 | 1 | 1 | 17µs | 17µs | URI::Escape::CORE:regcomp (opcode) |
| 1 | 1 | 1 | 15µs | 18µs | URI::Escape::uri_unescape |
| 1 | 1 | 1 | 13µs | 84µs | URI::Escape::BEGIN@142 |
| 2 | 1 | 1 | 10µs | 10µs | URI::Escape::CORE:qr (opcode) |
| 4 | 2 | 1 | 9µs | 9µs | URI::Escape::CORE:subst (opcode) |
| 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 | 68µs | 2 | 30µs | # spent 26µs (22+4) within URI::Escape::BEGIN@2 which was called:
# once (22µs+4µs) by C4::Output::BEGIN@31 at line 2 # spent 26µ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 | 97µs | 2 | 156µs | # spent 84µs (13+72) within URI::Escape::BEGIN@142 which was called:
# once (13µs+72µs) by C4::Output::BEGIN@31 at line 142 # spent 84µs making 1 call to URI::Escape::BEGIN@142
# spent 72µs making 1 call to vars::import |
| 143 | 3 | 70µs | 2 | 114µs | # spent 85µs (57+29) within URI::Escape::BEGIN@143 which was called:
# once (57µs+29µs) by C4::Output::BEGIN@31 at line 143 # spent 85µs making 1 call to URI::Escape::BEGIN@143
# spent 29µs making 1 call to vars::import |
| 144 | |||||
| 145 | 1 | 900ns | require Exporter; | ||
| 146 | 1 | 10µs | @ISA = qw(Exporter); | ||
| 147 | 1 | 900ns | @EXPORT = qw(uri_escape uri_unescape uri_escape_utf8); | ||
| 148 | 1 | 400ns | @EXPORT_OK = qw(%escapes); | ||
| 149 | 1 | 400ns | $VERSION = "3.30"; | ||
| 150 | |||||
| 151 | 3 | 466µ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 | 2µs | for (0..255) { | ||
| 155 | 256 | 393µs | $escapes{chr($_)} = sprintf("%%%02X", $_); | ||
| 156 | } | ||||
| 157 | |||||
| 158 | 1 | 400ns | my %subst; # compiled patterns | ||
| 159 | |||||
| 160 | 1 | 22µs | 2 | 10µs | my %Unsafe = ( # spent 10µ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 148µs (103+45) within URI::Escape::uri_escape which was called 3 times, avg 49µs/call:
# once (75µs+28µs) by main::RUNTIME at line 648 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (21µs+16µs) by C4::Search::buildQuery at line 1508 of /usr/share/koha/lib/C4/Search.pm
# once (6µs+1µs) by C4::Search::buildQuery at line 1509 of /usr/share/koha/lib/C4/Search.pm | ||||
| 167 | 12 | 24µs | my($text, $patn) = @_; | ||
| 168 | return undef unless defined $text; | ||||
| 169 | 3 | 105µ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 | 24µs | 24 | 46µs | $text =~ s/($Unsafe{RFC3986})/$escapes{$1} || _fail_hi($1)/ge; # spent 22µs making 18 calls to URI::Escape::CORE:substcont, avg 1µs/call
# spent 17µs making 3 calls to URI::Escape::CORE:regcomp, avg 6µs/call
# spent 6µs making 3 calls to URI::Escape::CORE:subst, avg 2µ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 18µs (15+3) within URI::Escape::uri_unescape which was called:
# once (15µ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 | 18µ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 | 10µs | 1; | ||
# spent 10µs within URI::Escape::CORE:qr which was called 2 times, avg 5µs/call:
# 2 times (10µs+0s) by C4::Output::BEGIN@31 at line 160, avg 5µs/call | |||||
# spent 17µs within URI::Escape::CORE:regcomp which was called 3 times, avg 6µs/call:
# 3 times (17µs+0s) by URI::Escape::uri_escape at line 178, avg 6µs/call | |||||
sub URI::Escape::CORE:subst; # opcode | |||||
# spent 22µs within URI::Escape::CORE:substcont which was called 18 times, avg 1µs/call:
# 18 times (22µs+0s) by URI::Escape::uri_escape at line 178, avg 1µs/call |