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

ruby-changes:49964

From: normal <ko1@a...>
Date: Mon, 29 Jan 2018 06:07:20 +0900 (JST)
Subject: [ruby-changes:49964] normal:r62081 (trunk): uri/common: reduce allocations and retained objects

normal	2018-01-29 06:07:13 +0900 (Mon, 29 Jan 2018)

  New Revision: 62081

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

  Log:
    uri/common: reduce allocations and retained objects
    
    Thanks to Sam Saffron for this patch, it shows
    a nice reduction which affects many web applications:
    
      require 'memory_profiler'
    
      MemoryProfiler.report do
        require 'uri'
      end.pretty_print
    
    Before:
    
    Total allocated: 986643 bytes (15159 objects)
    Total retained:  246370 bytes (2532 objects)
    
    After:
    
    Total allocated: 926903 bytes (13665 objects)
    Total retained:  208570 bytes (1587 objects)
    
    * lib/uri/common.rb: reduce allocations and retained objects
      [ruby-core:85161] [Feature #14410]

  Modified files:
    trunk/lib/uri/common.rb
Index: lib/uri/common.rb
===================================================================
--- lib/uri/common.rb	(revision 62080)
+++ lib/uri/common.rb	(revision 62081)
@@ -1,4 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L1
-# frozen_string_literal: false
+# frozen_string_literal: true
 #--
 # = uri/common.rb
 #
@@ -342,17 +342,17 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L342
 
   TBLENCWWWCOMP_ = {} # :nodoc:
   256.times do |i|
-    TBLENCWWWCOMP_[i.chr] = '%%%02X' % i
+    TBLENCWWWCOMP_[-i.chr] = -('%%%02X' % i)
   end
   TBLENCWWWCOMP_[' '] = '+'
   TBLENCWWWCOMP_.freeze
   TBLDECWWWCOMP_ = {} # :nodoc:
   256.times do |i|
     h, l = i>>4, i&15
-    TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr
-    TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr
-    TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr
-    TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr
+    TBLDECWWWCOMP_[-('%%%X%X' % [h, l])] = -i.chr
+    TBLDECWWWCOMP_[-('%%%x%X' % [h, l])] = -i.chr
+    TBLDECWWWCOMP_[-('%%%X%x' % [h, l])] = -i.chr
+    TBLDECWWWCOMP_[-('%%%x%x' % [h, l])] = -i.chr
   end
   TBLDECWWWCOMP_['+'] = ' '
   TBLDECWWWCOMP_.freeze
@@ -468,7 +468,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L468
       if isindex
         if sep.empty?
           val = key
-          key = ''
+          key = +''
         end
         isindex = false
       end
@@ -482,7 +482,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L482
       if val
         val.gsub!(/\+|%\h\h/, TBLDECWWWCOMP_)
       else
-        val = ''
+        val = +''
       end
 
       ary << [key, val]

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

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