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

ruby-changes:48179

From: k0kubun <ko1@a...>
Date: Sun, 22 Oct 2017 00:02:51 +0900 (JST)
Subject: [ruby-changes:48179] k0kubun:r60293 (trunk): erb.rb: specify frozen_string_literal: true

k0kubun	2017-10-22 00:02:46 +0900 (Sun, 22 Oct 2017)

  New Revision: 60293

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

  Log:
    erb.rb: specify frozen_string_literal: true
    
    for compilation performance.
    
    $ ruby ./benchmark/driver.rb -e "trunk::/Users/k0kubun/.rbenv/versions/trunk/bin/ruby;modified::/Users/k0kubun/.rbenv/versions/modified/bin/ruby" -d ./benchmark -p app_erb
    
    -----------------------------------------------------------
    benchmark results:
    Execution time (sec)
    name    trunk   modified
    app_erb 1.911      1.885
    
    Speedup ratio: compare with the result of `trunk' (greater is better)
    name    modified
    app_erb    1.014

  Modified files:
    trunk/lib/erb.rb
Index: lib/erb.rb
===================================================================
--- lib/erb.rb	(revision 60292)
+++ lib/erb.rb	(revision 60293)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L1
 # -*- coding: us-ascii -*-
-# frozen_string_literal: false
+# frozen_string_literal: true
 # = ERB -- Ruby Templating
 #
 # Author:: Masatoshi SEKI
@@ -547,7 +547,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L547
       def initialize(compiler, enc=nil, frozen=nil)
         @compiler = compiler
         @line = []
-        @script = ''
+        @script = +''
         @script << "#coding:#{enc}\n" if enc
         @script << "#frozen-string-literal:#{frozen}\n" unless frozen.nil?
         @compiler.pre_cmd.each do |x|
@@ -602,7 +602,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L602
       magic_comment = detect_magic_comment(s, enc)
       out = Buffer.new(self, *magic_comment)
 
-      self.content = ''
+      self.content = +''
       scanner = make_scanner(s)
       scanner.scan do |token|
         next if token.nil?
@@ -622,7 +622,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L622
       case stag
       when PercentLine
         add_put_cmd(out, content) if content.size > 0
-        self.content = ''
+        self.content = +''
         out.push(stag.to_s)
         out.cr
       when :cr
@@ -630,11 +630,11 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L630
       when '<%', '<%=', '<%#'
         scanner.stag = stag
         add_put_cmd(out, content) if content.size > 0
-        self.content = ''
+        self.content = +''
       when "\n"
         content << "\n"
         add_put_cmd(out, content)
-        self.content = ''
+        self.content = +''
       when '<%%'
         content << '<%'
       else
@@ -647,7 +647,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L647
       when '%>'
         compile_content(scanner.stag, out)
         scanner.stag = nil
-        self.content = ''
+        self.content = +''
       when '%%>'
         content << '%>'
       else

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

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