summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHongli Lai (Phusion) <hongli@phusion.nl>2009-04-15 00:32:29 +0200
committerHongli Lai (Phusion) <hongli@phusion.nl>2009-04-15 10:23:33 +0200
commite6095805ef67b59d18a9afa4a51345b500ab7f39 (patch)
treea06aa489b134604dc09338f0e6d12fe3622594db
parent385f621683f0be8fdce820bd900f39f5c904f89f (diff)
downloadrack-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.rb6
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