[前][次][番号順一覧][スレッド一覧]

ruby-changes:34993

From: naruse <ko1@a...>
Date: Wed, 6 Aug 2014 04:09:51 +0900 (JST)
Subject: [ruby-changes:34993] naruse:r47075 (trunk): * lib/net/http/generic_request.rb

naruse	2014-08-06 04:09:43 +0900 (Wed, 06 Aug 2014)

  New Revision: 47075

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47075

  Log:
    * lib/net/http/generic_request.rb
      (Net::HTTP::GenericRequest#initialize):
      optimize object allocation.

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/http/generic_request.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47074)
+++ ChangeLog	(revision 47075)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Aug  6 02:16:43 2014  NARUSE, Yui  <naruse@r...>
+
+	* lib/net/http/generic_request.rb
+	  (Net::HTTP::GenericRequest#initialize):
+	  optimize object allocation.
+
 Wed Aug  6 01:16:47 2014  NARUSE, Yui  <naruse@r...>
 
 	* lib/uri/generic.rb (URI::Generic#path_query): remove a private method.
Index: lib/net/http/generic_request.rb
===================================================================
--- lib/net/http/generic_request.rb	(revision 47074)
+++ lib/net/http/generic_request.rb	(revision 47075)
@@ -14,19 +14,18 @@ class Net::HTTPGenericRequest https://github.com/ruby/ruby/blob/trunk/lib/net/http/generic_request.rb#L14
 
     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 https://github.com/ruby/ruby/blob/trunk/lib/net/http/generic_request.rb#L43
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]