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 3EABD200CA; Tue, 7 Apr 2015 21:34:46 +0000 (UTC) Date: Tue, 7 Apr 2015 21:34:46 +0000 From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH] proxy_pass: avoid needless regexp Message-ID: <20150407213446.GB20108@dcvr.yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: A dumb string comparison will do here, so there's no point in paying the memory and CPU cost of a regexp match when we already extracted the suffix from a header key. --- lib/yahns/proxy_pass.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/yahns/proxy_pass.rb b/lib/yahns/proxy_pass.rb index 48a61af..1b8eed7 100644 --- a/lib/yahns/proxy_pass.rb +++ b/lib/yahns/proxy_pass.rb @@ -223,7 +223,8 @@ class Yahns::ProxyPass # :nodoc: # header in the request next if /\A(?:VERSION|CONNECTION|KEEP_ALIVE|X_FORWARDED_FOR|TRAILER)/ =~ key - chunked = true if %r{\ATRANSFER_ENCODING} =~ key && val =~ /\bchunked\b/i + 'TRANSFER_ENCODING'.freeze == key && val =~ /\bchunked\b/i and + chunked = true key.tr!('_'.freeze, '-'.freeze) req << "#{key}: #{val}\r\n" end -- EW