diff options
author | Eric Wong <e@80x24.org> | 2015-06-30 02:38:55 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-06-30 02:46:02 +0000 |
commit | 0d1ec2d1b864f3d39b4bf67fa6ac6c4aedc18136 (patch) | |
tree | d3ebbf2b0c4b1081d32ec6cdc82142e59e007ea5 /lib/yahns/max_body.rb | |
parent | baaebed4d7c50a3f14fbada767bada6fc2f0c8b5 (diff) | |
download | yahns-0d1ec2d1b864f3d39b4bf67fa6ac6c4aedc18136.tar.gz |
Ruby (MRI) 2.1 optimizes allocations away on String#freeze with literal strings. Furthermore, Ruby 2.2 optimizes away literal string allocations when they are used as arguments to Hash#[] and Hash#[]= Thus we can avoid expensive constant lookups and cache overhead by taking advantage of advancements in Ruby. Since Ruby 2.2 has been out for 7 months, now; it ought to be safe to introduce minor performance regressions for folks using older Rubies (1.9.3+ remains supported) to benefit folks on the latest Ruby.
Diffstat (limited to 'lib/yahns/max_body.rb')
-rw-r--r-- | lib/yahns/max_body.rb | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/yahns/max_body.rb b/lib/yahns/max_body.rb index fadbddc..e52a10f 100644 --- a/lib/yahns/max_body.rb +++ b/lib/yahns/max_body.rb @@ -28,17 +28,13 @@ class Yahns::MaxBody # :nodoc: @limit = limit end - RACK_INPUT = "rack.input".freeze # :nodoc: - CONTENT_LENGTH = "CONTENT_LENGTH" # :nodoc: - HTTP_TRANSFER_ENCODING = "HTTP_TRANSFER_ENCODING" # :nodoc: - # our main Rack middleware endpoint def call(env) # :nodoc: catch(:yahns_EFBIG) do - len = env[CONTENT_LENGTH] + len = env['CONTENT_LENGTH'] if len && len.to_i > @limit return err - elsif /\Achunked\z/i =~ env[HTTP_TRANSFER_ENCODING] + elsif /\Achunked\z/i =~ env['HTTP_TRANSFER_ENCODING'] limit_input!(env) end @app.call(env) @@ -51,9 +47,9 @@ class Yahns::MaxBody # :nodoc: end def limit_input!(env) # :nodoc: - input = env[RACK_INPUT] + input = env['rack.input'] klass = input.respond_to?(:rewind) ? RewindableWrapper : Wrapper - env[RACK_INPUT] = klass.new(input, @limit) + env['rack.input'] = klass.new(input, @limit) end end require_relative 'max_body/wrapper' |