Skip to content
Browse files

xml_mini.rb:_dasherize() replacement 20 to 25% faster

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 851a4ea commit 372d72445ba7cb2d79b2b087a51214f3c3d3d835 @mikehoward mikehoward committed with josevalim May 8, 2011
Showing with 3 additions and 4 deletions.
  1. +3 −4 activesupport/lib/active_support/xml_mini.rb
View
7 activesupport/lib/active_support/xml_mini.rb
@@ -139,10 +139,9 @@ def rename_key(key, options = {})
protected
def _dasherize(key)
- left = key.strip.rpartition(/^_*/)
- right = left.pop.partition(/_*$/)
- right.first.tr!('_ ', '--')
- left.concat(right).join
+ # $2 must be a non-greedy regex for this to work
+ left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1,3]
+ "#{left}#{middle.tr('_', '-')}#{right}"
end
# TODO: Add support for other encodings

0 comments on commit 372d724

Please sign in to comment.
Something went wrong with that request. Please try again.