* [PATCH] http_context: avoid defining our own *buffer_tmpdir methods
@ 2015-04-07 20:22 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-04-07 20:22 UTC (permalink / raw)
To: yahns-public
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.
---
lib/yahns/http_context.rb | 14 +++-----------
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
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-04-07 20:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-07 20:22 [PATCH] http_context: avoid defining our own *buffer_tmpdir methods Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/yahns.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).