提交 372d7244 编写于 作者: M Mike Howard 提交者: José Valim

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

Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 851a4eab
...@@ -139,10 +139,9 @@ def rename_key(key, options = {}) ...@@ -139,10 +139,9 @@ def rename_key(key, options = {})
protected protected
def _dasherize(key) def _dasherize(key)
left = key.strip.rpartition(/^_*/) # $2 must be a non-greedy regex for this to work
right = left.pop.partition(/_*$/) left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1,3]
right.first.tr!('_ ', '--') "#{left}#{middle.tr('_', '-')}#{right}"
left.concat(right).join
end end
# TODO: Add support for other encodings # TODO: Add support for other encodings
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册