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,AWL,BAYES_00 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 086FD1F7B2; Thu, 20 Nov 2014 20:45:52 +0000 (UTC) From: Eric Wong To: yahns-public@yhbt.net Cc: e@80x24.org Subject: [PATCH 4/6] http_response: reduce constants for 100 responses Date: Thu, 20 Nov 2014 20:45:40 +0000 Message-Id: <1416516342-18987-5-git-send-email-e@80x24.org> X-Mailer: git-send-email 2.2.0.rc0.dirty In-Reply-To: <1416516342-18987-1-git-send-email-e@80x24.org> References: <1416516342-18987-1-git-send-email-e@80x24.org> List-Id: Ruby 2.1 optimizes String#freeze by deduplicating string literal calls to freeze. Ruby 2.2 _may_ also optimize away allocations to Hash#delete in the future. In any case, this is uncommon code and not worth trading permanent space to reduce temporal garbage. While this favors Ruby 2.1 and later, it remains completely compatible with Ruby 1.9.3 and 2.0.0. --- lib/yahns/http_response.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb index e48e57c..0b0296f 100644 --- a/lib/yahns/http_response.rb +++ b/lib/yahns/http_response.rb @@ -28,9 +28,6 @@ module Yahns::HttpResponse # :nodoc: Z = "" CCC_RESPONSE_START = [ 'HTTP', '/1.1 ' ] RESPONSE_START = CCC_RESPONSE_START.join - R100_RAW = "HTTP/1.1 100 Continue\r\n\r\n" - R100_CCC = "100 Continue\r\n\r\nHTTP/1.1 " - HTTP_EXPECT = "HTTP_EXPECT" REQUEST_METHOD = "REQUEST_METHOD" HEAD = "HEAD" @@ -258,8 +255,10 @@ module Yahns::HttpResponse # :nodoc: # returns nil on success # returns :close, :wait_writable, or :wait_readable def http_100_response(env) - env.delete(HTTP_EXPECT) =~ /\A100-continue\z/i or return nil - buf = @response_start_sent ? R100_CCC : R100_RAW + env.delete("HTTP_EXPECT") =~ /\A100-continue\z/i or return + buf = @response_start_sent ? "100 Continue\r\n\r\nHTTP/1.1 ".freeze + : "HTTP/1.1 100 Continue\r\n\r\n".freeze + case rv = kgio_trywrite(buf) when String buf = rv -- EW