Permalink
Browse files

Improve performance of Multibyte::Utils.

Replace explicit for-loops by faster enumeration methods.

[#3158]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent 374e49b commit 2d3c58068c2f35e0a63d67a11685d1e5057412ff @Manfred Manfred committed with jeremy Nov 2, 2009
Showing with 6 additions and 7 deletions.
  1. +6 −7 activesupport/lib/active_support/multibyte/utils.rb
@@ -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
@@ -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

0 comments on commit 2d3c580

Please sign in to comment.