зеркало из https://github.com/github/ruby.git
* ext/psych/lib/psych/visitors/to_ruby.rb: speed up node mapping so
common cases are evaluated first. Thanks Kevin Menard! git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
c60e45f100
Коммит
4654d75ea3
|
@ -1,3 +1,8 @@
|
|||
Tue Dec 18 03:03:10 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||
|
||||
* ext/psych/lib/psych/visitors/to_ruby.rb: speed up node mapping so
|
||||
common cases are evaluated first. Thanks Kevin Menard!
|
||||
|
||||
Tue Dec 18 02:35:00 2012 Zachary Scott <zachary@zacharyscott.net>
|
||||
|
||||
* lib/optparse.rb: Remove 'developer documentation' section from rdoc
|
||||
|
|
|
@ -141,28 +141,6 @@ module Psych
|
|||
return revive_hash({}, o) unless o.tag
|
||||
|
||||
case o.tag
|
||||
when /^!(?:str|ruby\/string)(?::(.*))?/, 'tag:yaml.org,2002:str'
|
||||
klass = resolve_class($1)
|
||||
members = Hash[*o.children.map { |c| accept c }]
|
||||
string = members.delete 'str'
|
||||
|
||||
if klass
|
||||
string = klass.allocate.replace string
|
||||
register(o, string)
|
||||
end
|
||||
|
||||
init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)
|
||||
when /^!ruby\/array:(.*)$/
|
||||
klass = resolve_class($1)
|
||||
list = register(o, klass.allocate)
|
||||
|
||||
members = Hash[o.children.map { |c| accept c }.each_slice(2).to_a]
|
||||
list.replace members['internal']
|
||||
|
||||
members['ivars'].each do |ivar, v|
|
||||
list.instance_variable_set ivar, v
|
||||
end
|
||||
list
|
||||
when /^!ruby\/struct:?(.*)?$/
|
||||
klass = resolve_class($1)
|
||||
|
||||
|
@ -187,6 +165,43 @@ module Psych
|
|||
Struct.new(*h.map { |k,v| k.to_sym }).new(*h.map { |k,v| v })
|
||||
end
|
||||
|
||||
when /^!ruby\/object:?(.*)?$/
|
||||
name = $1 || 'Object'
|
||||
|
||||
if name == 'Complex'
|
||||
h = Hash[*o.children.map { |c| accept c }]
|
||||
register o, Complex(h['real'], h['image'])
|
||||
elsif name == 'Rational'
|
||||
h = Hash[*o.children.map { |c| accept c }]
|
||||
register o, Rational(h['numerator'], h['denominator'])
|
||||
else
|
||||
obj = revive((resolve_class(name) || Object), o)
|
||||
obj
|
||||
end
|
||||
|
||||
when /^!(?:str|ruby\/string)(?::(.*))?/, 'tag:yaml.org,2002:str'
|
||||
klass = resolve_class($1)
|
||||
members = Hash[*o.children.map { |c| accept c }]
|
||||
string = members.delete 'str'
|
||||
|
||||
if klass
|
||||
string = klass.allocate.replace string
|
||||
register(o, string)
|
||||
end
|
||||
|
||||
init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)
|
||||
when /^!ruby\/array:(.*)$/
|
||||
klass = resolve_class($1)
|
||||
list = register(o, klass.allocate)
|
||||
|
||||
members = Hash[o.children.map { |c| accept c }.each_slice(2).to_a]
|
||||
list.replace members['internal']
|
||||
|
||||
members['ivars'].each do |ivar, v|
|
||||
list.instance_variable_set ivar, v
|
||||
end
|
||||
list
|
||||
|
||||
when '!ruby/range'
|
||||
h = Hash[*o.children.map { |c| accept c }]
|
||||
register o, Range.new(h['begin'], h['end'], h['excl'])
|
||||
|
@ -206,19 +221,6 @@ module Psych
|
|||
end
|
||||
set
|
||||
|
||||
when '!ruby/object:Complex'
|
||||
h = Hash[*o.children.map { |c| accept c }]
|
||||
register o, Complex(h['real'], h['image'])
|
||||
|
||||
when '!ruby/object:Rational'
|
||||
h = Hash[*o.children.map { |c| accept c }]
|
||||
register o, Rational(h['numerator'], h['denominator'])
|
||||
|
||||
when /^!ruby\/object:?(.*)?$/
|
||||
name = $1 || 'Object'
|
||||
obj = revive((resolve_class(name) || Object), o)
|
||||
obj
|
||||
|
||||
when /^!map:(.*)$/, /^!ruby\/hash:(.*)$/
|
||||
revive_hash resolve_class($1).new, o
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче