* lib/uri/generic.rb (URI::Generic#normalize!): use String#empty?

* lib/uri/generic.rb (URI::Generic#path_query): optimized.

* lib/uri/generic.rb (URI::Generic#to_s): optimized.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2014-08-05 19:09:05 +00:00
parent a5c923f6c1
commit d7b5ef028b
2 changed files with 20 additions and 16 deletions

View File

@ -1,3 +1,11 @@
Wed Aug 6 01:15:47 2014 NARUSE, Yui <naruse@ruby-lang.org>
* lib/uri/generic.rb (URI::Generic#normalize!): use String#empty?
* lib/uri/generic.rb (URI::Generic#path_query): optimized.
* lib/uri/generic.rb (URI::Generic#to_s): optimized.
Wed Aug 6 00:15:10 2014 NARUSE, Yui <naruse@ruby-lang.org> Wed Aug 6 00:15:10 2014 NARUSE, Yui <naruse@ruby-lang.org>
* lib/uri/http.rb (URI::HTTP#request_uri): optimized. * lib/uri/http.rb (URI::HTTP#request_uri): optimized.

View File

@ -1329,7 +1329,7 @@ module URI
# Destructive version of #normalize # Destructive version of #normalize
# #
def normalize! def normalize!
if path && path == '' if path && path.empty?
set_path('/') set_path('/')
end end
if scheme && scheme != scheme.downcase if scheme && scheme != scheme.downcase
@ -1342,11 +1342,7 @@ module URI
# returns the assemble String with path and query components # returns the assemble String with path and query components
def path_query def path_query
str = @path @query ? "#@path?#@query" : @path
if @query
str += '?' + @query
end
str
end end
private :path_query private :path_query
@ -1357,36 +1353,36 @@ module URI
str = '' str = ''
if @scheme if @scheme
str << @scheme str << @scheme
str << ':' str << ':'.freeze
end end
if @opaque if @opaque
str << @opaque str << @opaque
else else
if @host if @host
str << '//' str << '//'.freeze
end end
if self.userinfo if self.userinfo
str << self.userinfo str << self.userinfo
str << '@' str << '@'.freeze
end end
if @host if @host
str << @host str << @host
end end
if @port && @port != self.default_port if @port && @port != self.default_port
str << ':' str << ':'.freeze
str << @port.to_s str << @port.to_s
end end
str << @path
str << path_query if @query
str << '?'.freeze
str << @query
end
end end
if @fragment if @fragment
str << '#' str << '#'.freeze
str << @fragment str << @fragment
end end
str str
end end