Skip to content

Commit

Permalink
Set HashTransliterator default replacement char only once
Browse files Browse the repository at this point in the history
If a string is 1000 characters longs, the previous code would check
1000 times if the `replacement` argument was nil, then fallback to
`DEFAULT_REPLACEMENT_CHAR`

By setting in the method's argument definition the default value
once, we skip this potentiel unnecessary check.
  • Loading branch information
czj authored Nov 16, 2016
1 parent 1e47f92 commit f6a4294
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/i18n/backend/transliterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def initialize(rule = nil)
add rule if rule
end

def transliterate(string, replacement = nil)
def transliterate(string, replacement = DEFAULT_REPLACEMENT_CHAR)
string.gsub(/[^\x00-\x7f]/u) do |char|
approximations[char] || replacement || DEFAULT_REPLACEMENT_CHAR
approximations[char] || replacement
end
end

Expand All @@ -96,4 +96,4 @@ def add(hash)
end
end
end
end
end

0 comments on commit f6a4294

Please sign in to comment.