diff options
author | Mike Howard <mike@clove.com> | 2011-05-08 09:08:56 -0600 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-05-09 17:06:56 +0200 |
commit | 372d72445ba7cb2d79b2b087a51214f3c3d3d835 (patch) | |
tree | 9277e4f0b1fa38136705724b4c6a41e087394cb7 /activesupport/lib/active_support | |
parent | 851a4eab3c06cb436d58f67782e484372c8ed53a (diff) | |
download | rails-372d72445ba7cb2d79b2b087a51214f3c3d3d835.tar.gz rails-372d72445ba7cb2d79b2b087a51214f3c3d3d835.tar.bz2 rails-372d72445ba7cb2d79b2b087a51214f3c3d3d835.zip |
xml_mini.rb:_dasherize() replacement 20 to 25% faster
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/xml_mini.rb | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index d8f40ab8b1..5cadcf634b 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -139,10 +139,9 @@ module ActiveSupport 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 |