Skip to content

Commit cfa5778

Browse files
authored
Merge pull request rails#46586 from SeanLF/main
Improve `ActiveSupport::Inflector.transliterate` performance [Fix rails#46569]
2 parents fae0bae + 8194f8e commit cfa5778

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

activesupport/lib/active_support/inflector/transliterate.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ module Inflector
6262
# Transliteration is restricted to UTF-8, US-ASCII, and GB18030 strings.
6363
# Other encodings will raise an ArgumentError.
6464
def transliterate(string, replacement = "?", locale: nil)
65-
string = string.dup if string.frozen?
6665
raise ArgumentError, "Can only transliterate strings. Received #{string.class.name}" unless string.is_a?(String)
6766
raise ArgumentError, "Cannot transliterate strings with #{string.encoding} encoding" unless ALLOWED_ENCODINGS_FOR_TRANSLITERATE.include?(string.encoding)
6867

68+
string = string.dup if string.frozen?
69+
return string if string.ascii_only?
70+
6971
input_encoding = string.encoding
7072

7173
# US-ASCII is a subset of UTF-8 so we'll force encoding as UTF-8 if

0 commit comments

Comments
 (0)