Skip to content

Commit fd8ef89

Browse files
committed
Changed to frozen_string_literal: true.
## Why? Because `s.check("a")` is slower than `s.check("a".freeze)`. - benchmark/stringscan_2.yaml ``` loop_count: 100000 contexts: - name: No YJIT prelude: | $LOAD_PATH.unshift(File.expand_path("lib")) require 'rexml' prelude: | require 'strscan' s = StringScanner.new('abcdefg hijklmn opqrstu vwxyz') ptn = "a" benchmark: 'check("a")' : s.check("a") 'check("a".freeze)' : s.check("a".freeze) 'ptn="a";s.check(ptn)' : | ptn="a" s.check(ptn) 'check(ptn)' : s.check(ptn) ``` ``` $benchmark-driver benchmark/stringscan_2.yaml Comparison: check(ptn): 13524479.4 i/s check("a".freeze): 13433638.1 i/s - 1.01x slower check("a"): 10231225.8 i/s - 1.32x slower ptn="a";s.check(ptn): 10013017.0 i/s - 1.35x slower ```
1 parent fb7ba27 commit fd8ef89

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/rexml/parsers/baseparser.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# frozen_string_literal: false
1+
# frozen_string_literal: true
22
require_relative '../parseexception'
33
require_relative '../undefinednamespaceexception'
44
require_relative '../source'
@@ -462,8 +462,7 @@ def normalize( input, entities=nil, entity_filter=nil )
462462

463463
# Unescapes all possible entities
464464
def unnormalize( string, entities=nil, filter=nil )
465-
rv = string.clone
466-
rv.gsub!( /\r\n?/, "\n" )
465+
rv = string.gsub( /\r\n?/, "\n" )
467466
matches = rv.scan( REFERENCE_RE )
468467
return rv if matches.size == 0
469468
rv.gsub!( /&#0*((?:\d+)|(?:x[a-fA-F0-9]+));/ ) {

0 commit comments

Comments
 (0)