summaryrefslogtreecommitdiff
path: root/common.mk
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2019-11-03 20:51:30 -0800
committerAaron Patterson <tenderlove@github.com>2019-11-04 15:27:15 -0800
commitebbe396d3c89345a1c36c0b5154e314cc33e19b7 (patch)
tree7b98a8fe4547825ae876acb24af634d54ec6e285 /common.mk
parent7c3bc0aa13abf3d46382860f76abb609a60376d6 (diff)
Use ident hash for top-level recursion check
We track recursion in order to not infinite loop in ==, inspect, and similar methods by keeping a thread-local 1 or 2 level hash. This allows us to track when we have seen the same object (ex. using inspect) or same pair of objects (ex. using ==) in this stack before and to treat that differently. Previously both levels of this Hash used the object's memory_id as a key (using object_id would be slow and wasteful). Unfortunately, prettyprint (pp.rb) uses this thread local variable to "pretend" to be inspect and inherit its same recursion behaviour. This commit changes the top-level hash to be an identity hash and to use objects as keys instead of their object_ids. I'd like to have also converted the 2nd level hash to an ident hash, but it would have prevented an optimization which avoids allocating a 2nd level hash for only a single element, which we want to keep because it's by far the most common case. So the new format of this hash is: { object => true } (not paired) { lhs_object => rhs_object_memory_id } (paired, single object) { lhs_object => { rhs_object_memory_id => true, ... } } (paired, many objects) We must also update pp.rb to match this (using identity hashes).
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2644
Diffstat (limited to 'common.mk')
0 files changed, 0 insertions, 0 deletions