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

ruby-changes:46620

From: k0kubun <ko1@a...>
Date: Mon, 15 May 2017 22:38:11 +0900 (JST)
Subject: [ruby-changes:46620] k0kubun:r58735 (trunk): erb.rb: Use String#<< instead of #concat

k0kubun	2017-05-15 22:38:02 +0900 (Mon, 15 May 2017)

  New Revision: 58735

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

  Log:
    erb.rb: Use String#<< instead of #concat
    
    to optimize String concatenation on rendering.
    
    [fix GH-1612]

  Modified files:
    trunk/lib/erb.rb
Index: lib/erb.rb
===================================================================
--- lib/erb.rb	(revision 58734)
+++ lib/erb.rb	(revision 58735)
@@ -281,8 +281,8 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L281
   #
   #   compiler = ERB::Compiler.new('<>')
   #   compiler.pre_cmd    = ["_erbout=String.new"]
-  #   compiler.put_cmd    = "_erbout.concat"
-  #   compiler.insert_cmd = "_erbout.concat"
+  #   compiler.put_cmd    = "_erbout.<<"
+  #   compiler.insert_cmd = "_erbout.<<"
   #   compiler.post_cmd   = ["_erbout"]
   #
   #   code, enc = compiler.compile("Got <%= obj %>!\n")
@@ -291,7 +291,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L291
   # <i>Generates</i>:
   #
   #   #coding:UTF-8
-  #   _erbout=String.new; _erbout.concat "Got "; _erbout.concat(( obj ).to_s); _erbout.concat "!\n"; _erbout
+  #   _erbout=String.new; _erbout.<< "Got "; _erbout.<<(( obj ).to_s); _erbout.<< "!\n"; _erbout
   #
   # By default the output is sent to the print method.  For example:
   #
@@ -867,8 +867,8 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L867
   # requires the setup of an ERB _compiler_ object.
   #
   def set_eoutvar(compiler, eoutvar = '_erbout')
-    compiler.put_cmd = "#{eoutvar}.concat"
-    compiler.insert_cmd = "#{eoutvar}.concat"
+    compiler.put_cmd = "#{eoutvar}.<<"
+    compiler.insert_cmd = "#{eoutvar}.<<"
     compiler.pre_cmd = ["#{eoutvar} = String.new"]
     compiler.post_cmd = ["#{eoutvar}.force_encoding(__ENCODING__)"]
   end

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

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