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:
parent
851a4eab3c
commit
372d72445b
1 changed files with 3 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue