Filename | /usr/share/perl5/URI/_query.pm |
Statements | Executed 60 statements in 883µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2 | 1 | 1 | 38µs | 82µs | query_form | URI::_query::
4 | 2 | 1 | 34µs | 44µs | query | URI::_query::
1 | 1 | 1 | 12µs | 28µs | BEGIN@3 | URI::_query::
4 | 1 | 1 | 10µs | 10µs | CORE:match (opcode) | URI::_query::
1 | 1 | 1 | 8µs | 35µs | BEGIN@5 | URI::_query::
1 | 1 | 1 | 4µs | 4µs | BEGIN@4 | URI::_query::
0 | 0 | 0 | 0s | 0s | query_keywords | URI::_query::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package URI::_query; | ||||
2 | |||||
3 | 2 | 28µs | 2 | 43µs | # spent 28µs (12+15) within URI::_query::BEGIN@3 which was called:
# once (12µs+15µs) by URI::implementor at line 3 # spent 28µs making 1 call to URI::_query::BEGIN@3
# spent 15µs making 1 call to strict::import |
4 | 2 | 26µs | 1 | 4µs | # spent 4µs within URI::_query::BEGIN@4 which was called:
# once (4µs+0s) by URI::implementor at line 4 # spent 4µs making 1 call to URI::_query::BEGIN@4 |
5 | 2 | 736µs | 2 | 62µs | # spent 35µs (8+27) within URI::_query::BEGIN@5 which was called:
# once (8µs+27µs) by URI::implementor at line 5 # spent 35µs making 1 call to URI::_query::BEGIN@5
# spent 27µs making 1 call to Exporter::import |
6 | |||||
7 | sub query | ||||
8 | { | ||||
9 | 4 | 1µs | my $self = shift; | ||
10 | 4 | 27µs | 4 | 10µs | $$self =~ m,^([^?\#]*)(?:\?([^\#]*))?(.*)$,s or die; # spent 10µs making 4 calls to URI::_query::CORE:match, avg 2µs/call |
11 | |||||
12 | 4 | 2µs | if (@_) { | ||
13 | 2 | 600ns | my $q = shift; | ||
14 | 2 | 2µs | $$self = $1; | ||
15 | 2 | 800ns | if (defined $q) { | ||
16 | $q =~ s/([^$URI::uric])/ URI::Escape::escape_char($1)/ego; | ||||
17 | utf8::downgrade($q); | ||||
18 | $$self .= "?$q"; | ||||
19 | } | ||||
20 | 2 | 2µs | $$self .= $3; | ||
21 | } | ||||
22 | 4 | 13µs | $2; | ||
23 | } | ||||
24 | |||||
25 | # Handle ...?foo=bar&bar=foo type of query | ||||
26 | # spent 82µs (38+44) within URI::_query::query_form which was called 2 times, avg 41µs/call:
# 2 times (38µs+44µs) by Search::Elasticsearch::Role::Cxn::HTTP::build_uri at line 94 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/Cxn/HTTP.pm, avg 41µs/call | ||||
27 | 2 | 1µs | my $self = shift; | ||
28 | 2 | 7µs | 2 | 26µs | my $old = $self->query; # spent 26µs making 2 calls to URI::_query::query, avg 13µs/call |
29 | 2 | 2µs | if (@_) { | ||
30 | # Try to set query string | ||||
31 | 2 | 200ns | my $delim; | ||
32 | 2 | 800ns | my $r = $_[0]; | ||
33 | 2 | 4µs | if (ref($r) eq "ARRAY") { | ||
34 | $delim = $_[1]; | ||||
35 | @_ = @$r; | ||||
36 | } | ||||
37 | elsif (ref($r) eq "HASH") { | ||||
38 | 2 | 600ns | $delim = $_[1]; | ||
39 | 2 | 2µs | @_ = %$r; | ||
40 | } | ||||
41 | 2 | 2µs | $delim = pop if @_ % 2; | ||
42 | |||||
43 | 2 | 500ns | my @query; | ||
44 | 2 | 3µs | while (my($key,$vals) = splice(@_, 0, 2)) { | ||
45 | $key = '' unless defined $key; | ||||
46 | $key =~ s/([;\/?:@&=+,\$\[\]%])/ URI::Escape::escape_char($1)/eg; | ||||
47 | $key =~ s/ /+/g; | ||||
48 | $vals = [ref($vals) eq "ARRAY" ? @$vals : $vals]; | ||||
49 | for my $val (@$vals) { | ||||
50 | $val = '' unless defined $val; | ||||
51 | $val =~ s/([;\/?:@&=+,\$\[\]%])/ URI::Escape::escape_char($1)/eg; | ||||
52 | $val =~ s/ /+/g; | ||||
53 | push(@query, "$key=$val"); | ||||
54 | } | ||||
55 | } | ||||
56 | 2 | 2µs | if (@query) { | ||
57 | unless ($delim) { | ||||
58 | $delim = $1 if $old && $old =~ /([&;])/; | ||||
59 | $delim ||= $URI::DEFAULT_QUERY_FORM_DELIMITER || "&"; | ||||
60 | } | ||||
61 | $self->query(join($delim, @query)); | ||||
62 | } | ||||
63 | else { | ||||
64 | 2 | 4µs | 2 | 18µs | $self->query(undef); # spent 18µs making 2 calls to URI::_query::query, avg 9µs/call |
65 | } | ||||
66 | } | ||||
67 | 2 | 10µs | return if !defined($old) || !length($old) || !defined(wantarray); | ||
68 | return unless $old =~ /=/; # not a form | ||||
69 | map { s/\+/ /g; uri_unescape($_) } | ||||
70 | map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/[&;]/, $old); | ||||
71 | } | ||||
72 | |||||
73 | # Handle ...?dog+bones type of query | ||||
74 | sub query_keywords | ||||
75 | { | ||||
76 | my $self = shift; | ||||
77 | my $old = $self->query; | ||||
78 | if (@_) { | ||||
79 | # Try to set query string | ||||
80 | my @copy = @_; | ||||
81 | @copy = @{$copy[0]} if @copy == 1 && ref($copy[0]) eq "ARRAY"; | ||||
82 | for (@copy) { s/([;\/?:@&=+,\$\[\]%])/ URI::Escape::escape_char($1)/eg; } | ||||
83 | $self->query(@copy ? join('+', @copy) : undef); | ||||
84 | } | ||||
85 | return if !defined($old) || !defined(wantarray); | ||||
86 | return if $old =~ /=/; # not keywords, but a form | ||||
87 | map { uri_unescape($_) } split(/\+/, $old, -1); | ||||
88 | } | ||||
89 | |||||
90 | # Some URI::URL compatibility stuff | ||||
91 | 1 | 2µs | *equery = \&query; | ||
92 | |||||
93 | 1 | 4µs | 1; | ||
# spent 10µs within URI::_query::CORE:match which was called 4 times, avg 2µs/call:
# 4 times (10µs+0s) by URI::_query::query at line 10, avg 2µs/call |