Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Optimize Plack::Request->query_parameters #384

Merged
merged 2 commits into from

2 participants

lestrrat Tatsuhiko Miyagawa
lestrrat
  • Old code used build an URI object (twice!), but for query parameter parsing, this is unnecessary
  • Stole code from URI::_query, directly created Hash::MultiValue
  • While we're at it, short-circuit the method by checking for cached instance before doing any parsing
  • This patch should make query parameter parsing about 5~10 times faster
lestrrat added some commits
lestrrat lestrrat Optimize ->query_parameters
* Old code used build an URI object (twice!), but for query parameter
  parsing, this is unnecessary
* Stole code from URI::_query, directly created Hash::MultiValue
* While we're at it, short-circuit the method by checking for cached
  instance before doing any parsing
* This patch should make query parameter parsing about 5~10 times faster
f365a0d
lestrrat lestrrat remove unnecessary ||= and replace with = 5c89616
Tatsuhiko Miyagawa miyagawa referenced this pull request from a commit
Tatsuhiko Miyagawa miyagawa Merge #384 a31f876
Tatsuhiko Miyagawa miyagawa referenced this pull request from a commit
Tatsuhiko Miyagawa miyagawa Cleanup request query caching #384 5413ff1
Tatsuhiko Miyagawa miyagawa merged commit 5c89616 into from
Tatsuhiko Miyagawa
Owner

Cleaned up in 5413ff1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 6, 2013
  1. lestrrat

    Optimize ->query_parameters

    lestrrat authored
    * Old code used build an URI object (twice!), but for query parameter
      parsing, this is unnecessary
    * Stole code from URI::_query, directly created Hash::MultiValue
    * While we're at it, short-circuit the method by checking for cached
      instance before doing any parsing
    * This patch should make query parameter parsing about 5~10 times faster
  2. lestrrat
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 3 deletions.
  1. +23 −3 lib/Plack/Request.pm
26 lib/Plack/Request.pm
View
@@ -77,10 +77,30 @@ sub cookies {
sub query_parameters {
my $self = shift;
- my @combined = $self->uri->query_form;
- @combined = (@combined, map { $_, '' } $self->uri->query_keywords);
- $self->env->{'plack.request.query'} ||= Hash::MultiValue->new(@combined);
+ my $env = $self->env;
+ my $query = $env->{'plack.request.query'};
+ if ($query) {
+ return $query;
+ }
+
+ my @query;
+ my $query_string = $env->{QUERY_STRING};
+ if (defined $query_string) {
+ if ($query_string =~ /=/) {
+ # Handle ?foo=bar&bar=foo type of query
+ @query =
+ map { s/\+/ /g; URI::Escape::uri_unescape($_) }
+ map { /=/ ? split(/=/, $_, 2) : ($_ => '')}
+ split(/[&;]/, $query_string);
+ } else {
+ # Handle ...?dog+bones type of query
+ @query =
+ map { (URI::Escape::uri_unescape($_), '') }
+ split(/\+/, $query_string, -1);
+ }
+ }
+ $env->{'plack.request.query'} = Hash::MultiValue->new(@query);
}
sub content {
Something went wrong with that request. Please try again.