1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Mike Howard 2011-05-08 09:08:56 -06:00 committed by José Valim
parent 851a4eab3c
commit 372d72445b

View file

@ -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