Skip to content

Commit

Permalink
Improve performance of Multibyte::Utils.
Browse files Browse the repository at this point in the history
Replace explicit for-loops by faster enumeration methods.

[#3158]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
Manfred authored and jeremy committed Mar 16, 2010
1 parent 374e49b commit 2d3c580
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions activesupport/lib/active_support/multibyte/utils.rb
Expand Up @@ -26,11 +26,11 @@ def self.verify(string)
else
def self.verify(string)
if expression = valid_character
for c in string.split(//)
return false unless expression.match(c)
end
# Splits the string on character boundaries, which are determined based on $KCODE.
string.split(//).all? { |c| expression.match(c) }
else
true
end
true
end
end

Expand All @@ -49,9 +49,8 @@ def self.clean(string)
else
def self.clean(string)
if expression = valid_character
stripped = []; for c in string.split(//)
stripped << c if expression.match(c)
end; stripped.join
# Splits the string on character boundaries, which are determined based on $KCODE.
string.split(//).grep(expression).join
else
string
end
Expand Down

0 comments on commit 2d3c580

Please sign in to comment.