mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
Use a monotonically increasing number for object_id
This changes object_id from being based on the objects location in memory (or a nearby memory location in the case of a conflict) to be based on an always increasing number. This number is a Ruby Integer which allows it to overflow the size of a pointer without issue (very unlikely to happen in real programs especially on 64-bit, but a nice guarantee). This changes obj_to_id_tbl and id_to_obj_tbl to both be maps of Ruby objects to Ruby objects (previously they were Ruby object to C integer) which simplifies updating them after compaction as we can run them through gc_update_table_refs. Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
This commit is contained in:
parent
d62abc47c8
commit
b99833baec
5 changed files with 90 additions and 151 deletions
8
hash.c
8
hash.c
|
@ -273,10 +273,14 @@ rb_objid_hash(st_index_t index)
|
|||
static st_index_t
|
||||
objid_hash(VALUE obj)
|
||||
{
|
||||
VALUE object_id = rb_obj_id(obj);
|
||||
if (!FIXNUM_P(object_id))
|
||||
object_id = rb_big_hash(object_id);
|
||||
|
||||
#if SIZEOF_LONG == SIZEOF_VOIDP
|
||||
return (st_index_t)st_index_hash((st_index_t)NUM2LONG(rb_obj_id(obj)));
|
||||
return (st_index_t)st_index_hash((st_index_t)NUM2LONG(object_id));
|
||||
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
|
||||
return (st_index_t)st_index_hash((st_index_t)NUM2LL(rb_obj_id(obj)));
|
||||
return (st_index_t)st_index_hash((st_index_t)NUM2LL(object_id));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue