From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,BAYES_00, T_RP_MATCHES_RCVD shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: yahns-public@yhbt.net Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id DCA2F1F5D6 for ; Tue, 7 Apr 2015 20:22:53 +0000 (UTC) From: Eric Wong 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 Message-Id: <1428438173-20485-1-git-send-email-e@80x24.org> List-Id: 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