* lib/pp.rb: use Hash for recursion check as inspect.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2007-12-07 06:45:28 +00:00
Родитель 62c94002ef
Коммит 9bc20bef7a
2 изменённых файлов: 10 добавлений и 6 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Fri Dec 7 15:44:40 2007 Tanaka Akira <akr@fsij.org>
* lib/pp.rb: use Hash for recursion check as inspect.
Fri Dec 7 15:04:01 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (flatten): some performance improvements, based on a patch

Просмотреть файл

@ -111,13 +111,13 @@ class PP < PrettyPrint
end
if Thread.current[:__recursive_key__][:inspect] == nil
Thread.current[:__recursive_key__][:inspect] = []
Thread.current[:__recursive_key__][:inspect] = {}
end
save = Thread.current[:__recursive_key__][:inspect]
begin
Thread.current[:__recursive_key__][:inspect] = []
Thread.current[:__recursive_key__][:inspect] = {}
yield
ensure
Thread.current[:__recursive_key__][:inspect] = save
@ -130,10 +130,10 @@ class PP < PrettyPrint
Thread.current[:__recursive_key__][:inspect].include?(id)
end
def push_inspect_key(id)
Thread.current[:__recursive_key__][:inspect] << id
Thread.current[:__recursive_key__][:inspect][id] = true
end
def pop_inspect_key
Thread.current[:__recursive_key__][:inspect].pop
def pop_inspect_key(id)
Thread.current[:__recursive_key__][:inspect].delete id
end
# Adds +obj+ to the pretty printing buffer
@ -153,7 +153,7 @@ class PP < PrettyPrint
push_inspect_key(id)
group {obj.pretty_print self}
ensure
pop_inspect_key unless PP.sharing_detection
pop_inspect_key(id) unless PP.sharing_detection
end
end