← Index
NYTProf Performance Profile   « line view »
For svc/members/upsert
  Run on Tue Jan 13 11:50:22 2015
Reported on Tue Jan 13 12:09:51 2015

Filename/usr/share/perl5/URI/QueryParam.pm
StatementsExecuted 5 statements in 445µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11111µs22µsURI::QueryParam::::BEGIN@3URI::QueryParam::BEGIN@3
1118µs17µsURI::QueryParam::::BEGIN@4URI::QueryParam::BEGIN@4
0000s0sURI::_query::::query_form_hash URI::_query::query_form_hash
0000s0sURI::_query::::query_param URI::_query::query_param
0000s0sURI::_query::::query_param_append URI::_query::query_param_append
0000s0sURI::_query::::query_param_delete URI::_query::query_param_delete
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package URI::QueryParam;
2
3226µs233µs
# spent 22µs (11+11) within URI::QueryParam::BEGIN@3 which was called: # once (11µs+11µs) by Authen::CAS::Client::BEGIN@11 at line 3
use strict;
# spent 22µs making 1 call to URI::QueryParam::BEGIN@3 # spent 11µs making 1 call to strict::import
42418µs225µs
# spent 17µs (8+8) within URI::QueryParam::BEGIN@4 which was called: # once (8µs+8µs) by Authen::CAS::Client::BEGIN@11 at line 4
use warnings;
# spent 17µs making 1 call to URI::QueryParam::BEGIN@4 # spent 8µs making 1 call to warnings::import
5
6sub URI::_query::query_param {
7 my $self = shift;
8 my @old = $self->query_form;
9
10 if (@_ == 0) {
11 # get keys
12 my (%seen, $i);
13 return grep !($i++ % 2 || $seen{$_}++), @old;
14 }
15
16 my $key = shift;
17 my @i = grep $_ % 2 == 0 && $old[$_] eq $key, 0 .. $#old;
18
19 if (@_) {
20 my @new = @old;
21 my @new_i = @i;
22 my @vals = map { ref($_) eq 'ARRAY' ? @$_ : $_ } @_;
23
24 while (@new_i > @vals) {
25 splice @new, pop @new_i, 2;
26 }
27 if (@vals > @new_i) {
28 my $i = @new_i ? $new_i[-1] + 2 : @new;
29 my @splice = splice @vals, @new_i, @vals - @new_i;
30
31 splice @new, $i, 0, map { $key => $_ } @splice;
32 }
33 if (@vals) {
34 #print "SET $new_i[0]\n";
35 @new[ map $_ + 1, @new_i ] = @vals;
36 }
37
38 $self->query_form(\@new);
39 }
40
41 return wantarray ? @old[map $_+1, @i] : @i ? $old[$i[0]+1] : undef;
42}
43
44sub URI::_query::query_param_append {
45 my $self = shift;
46 my $key = shift;
47 my @vals = map { ref $_ eq 'ARRAY' ? @$_ : $_ } @_;
48 $self->query_form($self->query_form, $key => \@vals); # XXX
49 return;
50}
51
52sub URI::_query::query_param_delete {
53 my $self = shift;
54 my $key = shift;
55 my @old = $self->query_form;
56 my @vals;
57
58 for (my $i = @old - 2; $i >= 0; $i -= 2) {
59 next if $old[$i] ne $key;
60 push(@vals, (splice(@old, $i, 2))[1]);
61 }
62 $self->query_form(\@old) if @vals;
63 return wantarray ? reverse @vals : $vals[-1];
64}
65
66sub URI::_query::query_form_hash {
67 my $self = shift;
68 my @old = $self->query_form;
69 if (@_) {
70 $self->query_form(@_ == 1 ? %{shift(@_)} : @_);
71 }
72 my %hash;
73 while (my($k, $v) = splice(@old, 0, 2)) {
74 if (exists $hash{$k}) {
75 for ($hash{$k}) {
76 $_ = [$_] unless ref($_) eq "ARRAY";
77 push(@$_, $v);
78 }
79 }
80 else {
81 $hash{$k} = $v;
82 }
83 }
84 return \%hash;
85}
86
8712µs1;
88
89__END__