Implement WeakKeyMap on VWA

Benchmark:

```
puts(Benchmark.measure do
  10_000_000.times do
    ObjectSpace::WeakKeyMap.new
  end
end)
```

Before:

```
2.554772   0.014167   2.568939 (  2.575763)
```

After:

```
1.994920   0.013583   2.008503 (  2.012139)
```
This commit is contained in:
Peter Zhu 2023-11-20 17:01:18 -05:00
parent de337a312f
commit c34d23fcc8

View File

@ -557,7 +557,6 @@ wkmap_free(void *ptr)
st_foreach(w->table, wkmap_free_table_i, 0);
st_free_table(w->table);
xfree(w);
}
static size_t
@ -565,7 +564,7 @@ wkmap_memsize(const void *ptr)
{
const struct weakkeymap *w = ptr;
size_t size = sizeof(*w);
size_t size = 0;
size += st_memsize(w->table);
/* Each key of the table takes sizeof(VALUE) in size. */
size += st_table_size(w->table) * sizeof(VALUE);
@ -619,7 +618,7 @@ static const rb_data_type_t weakkeymap_type = {
wkmap_memsize,
wkmap_compact,
},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
};
static int