diff options
author | Hongli Lai (Phusion) <hongli@phusion.nl> | 2009-04-15 00:32:29 +0200 |
---|---|---|
committer | Hongli Lai (Phusion) <hongli@phusion.nl> | 2009-04-15 10:23:33 +0200 |
commit | e6095805ef67b59d18a9afa4a51345b500ab7f39 (patch) | |
tree | a06aa489b134604dc09338f0e6d12fe3622594db | |
parent | 385f621683f0be8fdce820bd900f39f5c904f89f (diff) | |
download | rack-e6095805ef67b59d18a9afa4a51345b500ab7f39.tar.gz |
Optimize parse_multipart: put read data into a buffer in order to reduce garbage. This is allowed by the recent rack.input#read spec changes.
-rw-r--r-- | lib/rack/utils.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb index be29221e..6aaf4787 100644 --- a/lib/rack/utils.rb +++ b/lib/rack/utils.rb @@ -309,7 +309,9 @@ module Rack content_length -= boundary_size - status = input.read(boundary_size) + read_buffer = '' + + status = input.read(boundary_size, read_buffer) raise EOFError, "bad content body" unless status == boundary + EOL rx = /(?:#{EOL})?#{Regexp.quote boundary}(#{EOL}|--)/n @@ -341,7 +343,7 @@ module Rack body << buf.slice!(0, buf.size - (boundary_size+4)) end - c = input.read(bufsize < content_length ? bufsize : content_length) + c = input.read(bufsize < content_length ? bufsize : content_length, read_buffer) raise EOFError, "bad content body" if c.nil? || c.empty? buf << c content_length -= c.size |