From 372d72445ba7cb2d79b2b087a51214f3c3d3d835 Mon Sep 17 00:00:00 2001 From: Mike Howard Date: Sun, 8 May 2011 09:08:56 -0600 Subject: xml_mini.rb:_dasherize() replacement 20 to 25% faster MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/lib/active_support/xml_mini.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'activesupport/lib/active_support/xml_mini.rb') 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 -- cgit v1.2.3