diff options
author | Eric Wong <e@80x24.org> | 2015-04-07 20:22:53 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-04-07 20:24:37 +0000 |
commit | f1734dc1281de6c8c1f57ab798498cdf78967d75 (patch) | |
tree | 79079df9d6d8317455a954d21947fc52ff7153ed /lib | |
parent | 9ae8745eb06cd601d5c1f56eb1e3c4b0678508f8 (diff) | |
download | yahns-f1734dc1281de6c8c1f57ab798498cdf78967d75.tar.gz |
Instance variable attr methods are cheaper and we can shove the complexity down to tmpio by allowing it to accept a nil argument for the temporary directory. This adds 4 bytes to tmpio but removes over 1K in http_context on a 32-bit system.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/yahns/http_context.rb | 14 | ||||
-rw-r--r-- | lib/yahns/tmpio.rb | 4 |
2 files changed, 5 insertions, 13 deletions
diff --git a/lib/yahns/http_context.rb b/lib/yahns/http_context.rb index 73bb49a..13b8686 100644 --- a/lib/yahns/http_context.rb +++ b/lib/yahns/http_context.rb @@ -18,7 +18,7 @@ module Yahns::HttpContext # :nodoc: attr_reader :app attr_reader :app_defaults attr_writer :input_buffer_tmpdir - attr_writer :output_buffer_tmpdir + attr_accessor :output_buffer_tmpdir def http_ctx_init(yahns_rack) @yahns_rack = yahns_rack @@ -80,19 +80,11 @@ module Yahns::HttpContext # :nodoc: def tmpio_for(len) if len # Content-Length given len <= @client_body_buffer_size ? StringIO.new("") - : Yahns::TmpIO.new(input_buffer_tmpdir) + : Yahns::TmpIO.new(@input_buffer_tmpdir) else # chunked, unknown length mbs = @client_max_body_size - tmpdir = input_buffer_tmpdir + tmpdir = @input_buffer_tmpdir mbs ? Yahns::CapInput.new(mbs, tmpdir) : Yahns::TmpIO.new(tmpdir) end end - - def input_buffer_tmpdir - @input_buffer_tmpdir || Dir.tmpdir - end - - def output_buffer_tmpdir - @output_buffer_tmpdir || Dir.tmpdir - end end diff --git a/lib/yahns/tmpio.rb b/lib/yahns/tmpio.rb index d25d5e8..ca86b4e 100644 --- a/lib/yahns/tmpio.rb +++ b/lib/yahns/tmpio.rb @@ -12,10 +12,10 @@ class Yahns::TmpIO < File # :nodoc: # creates and returns a new File object. The File is unlinked # immediately, switched to binary mode, and userspace output # buffering is disabled - def self.new(tmpdir = Dir.tmpdir) + def self.new(dir) retried = false begin - fp = super("#{tmpdir}/#{rand}", RDWR|CREAT|EXCL|APPEND, 0600) + fp = super("#{dir || Dir.tmpdir}/#{rand}", RDWR|CREAT|EXCL|APPEND, 0600) rescue Errno::EEXIST retry rescue Errno::EMFILE, Errno::ENFILE |