зеркало из https://github.com/github/ruby.git
Implement WeakMap on VWA
Benchmark: ``` puts(Benchmark.measure do 10_000_000.times do ObjectSpace::WeakMap.new end end) ``` Before: ``` 2.568662 0.014001 2.582663 ( 2.601743) ``` After: ``` 2.025523 0.008676 2.034199 ( 2.041760) ```
This commit is contained in:
Родитель
57fa69f26f
Коммит
de337a312f
|
@ -88,7 +88,6 @@ wmap_free(void *ptr)
|
||||||
|
|
||||||
st_foreach(w->table, wmap_free_table_i, 0);
|
st_foreach(w->table, wmap_free_table_i, 0);
|
||||||
st_free_table(w->table);
|
st_free_table(w->table);
|
||||||
xfree(w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
|
@ -96,7 +95,7 @@ wmap_memsize(const void *ptr)
|
||||||
{
|
{
|
||||||
const struct weakmap *w = ptr;
|
const struct weakmap *w = ptr;
|
||||||
|
|
||||||
size_t size = sizeof(*w);
|
size_t size = 0;
|
||||||
size += st_memsize(w->table);
|
size += st_memsize(w->table);
|
||||||
/* The key and value of the table each take sizeof(VALUE) in size. */
|
/* The key and value of the table each take sizeof(VALUE) in size. */
|
||||||
size += st_table_size(w->table) * (2 * sizeof(VALUE));
|
size += st_table_size(w->table) * (2 * sizeof(VALUE));
|
||||||
|
@ -156,7 +155,7 @@ static const rb_data_type_t weakmap_type = {
|
||||||
wmap_memsize,
|
wmap_memsize,
|
||||||
wmap_compact,
|
wmap_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
|
static int
|
||||||
|
|
Загрузка…
Ссылка в новой задаче