From 159fa373f8e913a5464ab88c308e4375c946af8b Mon Sep 17 00:00:00 2001 From: naruse Date: Tue, 5 Aug 2014 19:09:43 +0000 Subject: * lib/net/http/generic_request.rb (Net::HTTP::GenericRequest#initialize): optimize object allocation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ lib/net/http/generic_request.rb | 17 ++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index e9f0e2ee4f..e888316216 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Aug 6 02:16:43 2014 NARUSE, Yui + + * lib/net/http/generic_request.rb + (Net::HTTP::GenericRequest#initialize): + optimize object allocation. + Wed Aug 6 01:16:47 2014 NARUSE, Yui * lib/uri/generic.rb (URI::Generic#path_query): remove a private method. diff --git a/lib/net/http/generic_request.rb b/lib/net/http/generic_request.rb index b51034c7ea..0b70630d89 100644 --- a/lib/net/http/generic_request.rb +++ b/lib/net/http/generic_request.rb @@ -14,19 +14,18 @@ class Net::HTTPGenericRequest if URI === uri_or_path then @uri = uri_or_path.dup - host = @uri.hostname - host += ":#{@uri.port}" if @uri.port != @uri.class::DEFAULT_PORT - path = uri_or_path.request_uri + host = @uri.hostname.dup + host << ":".freeze << @uri.port.to_s if @uri.port != @uri.default_port + @path = uri_or_path.request_uri + raise ArgumentError, "no HTTP request path given" unless @path else @uri = nil host = nil - path = uri_or_path + raise ArgumentError, "no HTTP request path given" unless uri_or_path + raise ArgumentError, "HTTP request path is empty" if uri_or_path.empty? + @path = uri_or_path.dup end - raise ArgumentError, "no HTTP request path given" unless path - raise ArgumentError, "HTTP request path is empty" if path.empty? - @path = path - @decode_content = false if @response_has_body and Net::HTTP::HAVE_ZLIB then @@ -44,7 +43,7 @@ class Net::HTTPGenericRequest initialize_http_header initheader self['Accept'] ||= '*/*' self['User-Agent'] ||= 'Ruby' - self['Host'] ||= host + self['Host'] ||= host if host @body = nil @body_stream = nil @body_data = nil -- cgit v1.2.3