From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH] http_context: avoid defining our own *buffer_tmpdir methods
Date: Tue, 7 Apr 2015 20:22:53 +0000 [thread overview]
Message-ID: <1428438173-20485-1-git-send-email-e@80x24.org> (raw)
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
reply other threads:[~2015-04-07 20:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/yahns/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1428438173-20485-1-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=yahns-public@yhbt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).