HTTP::Body, tried using APR::Request for urlencoded parsing, but Perl is faster....
Andy Grundman [Sat, 31 Mar 2007 04:39:54 +0000 (04:39 +0000)]
lib/HTTP/Body.pm
lib/HTTP/Body/UrlEncoded.pm

index e915bfa..9901022 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 
 use Carp       qw[ ];
 
-our $VERSION = 0.9;
+our $VERSION = 0.91;
 
 our $TYPES = {
     'application/octet-stream'          => 'HTTP::Body::OctetStream',
index 9545688..3d32562 100644 (file)
@@ -8,11 +8,9 @@ our $DECODE = qr/%([0-9a-fA-F]{2})/;
 
 our %hex_chr;
 
-BEGIN {
-    for my $num ( 0 .. 255 ) {
-        my $h = sprintf "%02X", $num;
-        $hex_chr{ lc $h } = $hex_chr{ uc $h } = chr $num;
-    }
+for my $num ( 0 .. 255 ) {
+    my $h = sprintf "%02X", $num;
+    $hex_chr{ lc $h } = $hex_chr{ uc $h } = chr $num;
 }
 
 =head1 NAME
@@ -40,7 +38,12 @@ sub spin {
 
     return unless $self->length == $self->content_length;
     
-    $self->{buffer} =~ tr/+/ /;
+    # I tested parsing this using APR::Request, but perl is faster
+    # Pure-Perl    2560/s
+    # APR::Request 2305/s
+    
+    # Note: s/// appears faster than tr///
+    $self->{buffer} =~ s/\+/ /g;
 
     for my $pair ( split( /[&;]/, $self->{buffer} ) ) {
 
@@ -61,10 +64,12 @@ sub spin {
 
 =back
 
-=head1 AUTHOR
+=head1 AUTHORS
 
 Christian Hansen, C<ch@ngmedia.com>
 
+Andy Grundman, C<andy@hybridized.org>
+
 =head1 LICENSE
 
 This library is free software . You can redistribute it and/or modify