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

ruby-changes:34991

From: naruse <ko1@a...>
Date: Wed, 6 Aug 2014 04:09:14 +0900 (JST)
Subject: [ruby-changes:34991] naruse:r47073 (trunk): * lib/uri/generic.rb (URI::Generic#normalize!): use String#empty?

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

  New Revision: 47073

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

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/lib/uri/generic.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47072)
+++ ChangeLog	(revision 47073)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Aug  6 01:15:47 2014  NARUSE, Yui  <naruse@r...>
+
+	* 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@r...>
 
 	* lib/uri/http.rb (URI::HTTP#request_uri): optimized.
Index: lib/uri/generic.rb
===================================================================
--- lib/uri/generic.rb	(revision 47072)
+++ lib/uri/generic.rb	(revision 47073)
@@ -1329,7 +1329,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L1329
     # Destructive version of #normalize
     #
     def normalize!
-      if path && path == ''
+      if path && path.empty?
         set_path('/')
       end
       if scheme && scheme != scheme.downcase
@@ -1342,11 +1342,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L1342
 
     # returns the assemble String with path and query components
     def path_query
-      str = @path
-      if @query
-        str += '?' + @query
-      end
-      str
+      @query ? "#@path?#@query" : @path
     end
     private :path_query
 
@@ -1357,36 +1353,36 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L1353
       str = ''
       if @scheme
         str << @scheme
-        str << ':'
+        str << ':'.freeze
       end
 
       if @opaque
         str << @opaque
-
       else
         if @host
-          str << '//'
+          str << '//'.freeze
         end
         if self.userinfo
           str << self.userinfo
-          str << '@'
+          str << '@'.freeze
         end
         if @host
           str << @host
         end
         if @port && @port != self.default_port
-          str << ':'
+          str << ':'.freeze
           str << @port.to_s
         end
-
-        str << path_query
+        str << @path
+        if @query
+          str << '?'.freeze
+          str << @query
+        end
       end
-
       if @fragment
-        str << '#'
+        str << '#'.freeze
         str << @fragment
       end
-
       str
     end
 

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

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