summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-26 12:12:13 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-26 12:12:13 +0000
commit5fc32362229e6ec14e2a32699975918fa9d68cfc (patch)
treeb892a7882b04c9e3ce3d95035717e7f3e16e11b5 /lib
parente3c140681a29ad4b9792eb163116ac96c3b8ef5e (diff)
erb.rb: Use script encoding instead of force_encoding
The original intention of introducing `_erbout.force_encoding` in r21170 was: - "returns a string in the same character encoding as the input string." - "When the input string has a magic comment, however, it returns a string in the encoding specified by the magic comment." And they are tested by test/erb/test_erb_m17n.rb well and this patch passes the test. Since magic comment is always added in ERB compiled code, using ''.dup instead of String.new will set correct encoding without calling force_encoding method. The benchmark results are: * Before $ ./ruby benchmark/run.rb --matzruby=./ruby -m bm_app_erb MatzRuby: ruby 2.5.0dev (2017-05-26 skip-force-enc.. 58903) [x86_64-linux] last_commit=Skip force_encoding in compiled code of erb Ruby: app_erb: matz 0.715 * After $ ./ruby benchmark/run.rb --matzruby=./ruby -m bm_app_erb MatzRuby: ruby 2.5.0dev (2017-05-26 skip-force-enc.. 58903) [x86_64-linux] last_commit=Skip force_encoding in compiled code of erb Ruby: app_erb: matz 0.672 And perf(1) results are: * Before $ sudo perf stat ./ruby benchmark/bm_app_erb.rb Performance counter stats for './ruby benchmark/bm_app_erb.rb': 709.571746 task-clock (msec) # 1.000 CPUs utilized 5 context-switches # 0.007 K/sec 1 cpu-migrations # 0.001 K/sec 1,337 page-faults # 0.002 M/sec 3,088,936,521 cycles # 4.353 GHz <not supported> stalled-cycles-frontend <not supported> stalled-cycles-backend 4,849,564,282 instructions # 1.57 insns per cycle 1,027,042,087 branches # 1447.411 M/sec 19,983,456 branch-misses # 1.95% of all branches 0.709747823 seconds time elapsed * After $ sudo perf stat ./ruby benchmark/bm_app_erb.rb Performance counter stats for './ruby benchmark/bm_app_erb.rb': 693.494673 task-clock (msec) # 1.000 CPUs utilized 7 context-switches # 0.010 K/sec 1 cpu-migrations # 0.001 K/sec 1,316 page-faults # 0.002 M/sec 3,025,639,349 cycles # 4.363 GHz <not supported> stalled-cycles-frontend <not supported> stalled-cycles-backend 4,694,848,271 instructions # 1.55 insns per cycle 994,496,704 branches # 1434.037 M/sec 19,693,239 branch-misses # 1.98% of all branches 0.693724345 seconds time elapsed [fix GH-1147] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/erb.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/erb.rb b/lib/erb.rb
index f367e32a97..cb7dbaf286 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -280,7 +280,7 @@ class ERB
# ERB#src:
#
# compiler = ERB::Compiler.new('<>')
- # compiler.pre_cmd = ["_erbout=String.new"]
+ # compiler.pre_cmd = ["_erbout=''.dup"]
# compiler.put_cmd = "_erbout.<<"
# compiler.insert_cmd = "_erbout.<<"
# compiler.post_cmd = ["_erbout"]
@@ -291,7 +291,7 @@ class ERB
# <i>Generates</i>:
#
# #coding:UTF-8
- # _erbout=String.new; _erbout.<< "Got "; _erbout.<<(( obj ).to_s); _erbout.<< "!\n"; _erbout
+ # _erbout=''.dup; _erbout.<< "Got "; _erbout.<<(( obj ).to_s); _erbout.<< "!\n"; _erbout
#
# By default the output is sent to the print method. For example:
#
@@ -861,8 +861,8 @@ class ERB
def set_eoutvar(compiler, eoutvar = '_erbout')
compiler.put_cmd = "#{eoutvar}.<<"
compiler.insert_cmd = "#{eoutvar}.<<"
- compiler.pre_cmd = ["#{eoutvar} = String.new"]
- compiler.post_cmd = ["#{eoutvar}.force_encoding(__ENCODING__)"]
+ compiler.pre_cmd = ["#{eoutvar} = ''.dup"]
+ compiler.post_cmd = [eoutvar]
end
# Generate results and print them. (see ERB#result)