Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 159fa37

Browse files
committed
* 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
1 parent b6ecbc7 commit 159fa37

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Wed Aug 6 02:16:43 2014 NARUSE, Yui <[email protected]>
2+
3+
* lib/net/http/generic_request.rb
4+
(Net::HTTP::GenericRequest#initialize):
5+
optimize object allocation.
6+
17
Wed Aug 6 01:16:47 2014 NARUSE, Yui <[email protected]>
28

39
* lib/uri/generic.rb (URI::Generic#path_query): remove a private method.

lib/net/http/generic_request.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@ def initialize(m, reqbody, resbody, uri_or_path, initheader = nil)
1414

1515
if URI === uri_or_path then
1616
@uri = uri_or_path.dup
17-
host = @uri.hostname
18-
host += ":#{@uri.port}" if @uri.port != @uri.class::DEFAULT_PORT
19-
path = uri_or_path.request_uri
17+
host = @uri.hostname.dup
18+
host << ":".freeze << @uri.port.to_s if @uri.port != @uri.default_port
19+
@path = uri_or_path.request_uri
20+
raise ArgumentError, "no HTTP request path given" unless @path
2021
else
2122
@uri = nil
2223
host = nil
23-
path = uri_or_path
24+
raise ArgumentError, "no HTTP request path given" unless uri_or_path
25+
raise ArgumentError, "HTTP request path is empty" if uri_or_path.empty?
26+
@path = uri_or_path.dup
2427
end
2528

26-
raise ArgumentError, "no HTTP request path given" unless path
27-
raise ArgumentError, "HTTP request path is empty" if path.empty?
28-
@path = path
29-
3029
@decode_content = false
3130

3231
if @response_has_body and Net::HTTP::HAVE_ZLIB then
@@ -44,7 +43,7 @@ def initialize(m, reqbody, resbody, uri_or_path, initheader = nil)
4443
initialize_http_header initheader
4544
self['Accept'] ||= '*/*'
4645
self['User-Agent'] ||= 'Ruby'
47-
self['Host'] ||= host
46+
self['Host'] ||= host if host
4847
@body = nil
4948
@body_stream = nil
5049
@body_data = nil

0 commit comments

Comments
 (0)