Implement Enumerator objects on VWA
This commit implements Enumerator objects on VWA. This speeds allocations and decreases memory usage. ``` require "benchmark" ary = [] puts(Benchmark.measure do 10_000_000.times do u = ary.to_enum end end) puts `ps -o rss= -p #{$$}` ``` Before: ``` 1.500774 0.002717 1.503491 ( 1.506791) 18512 ``` After: ``` 0.892580 0.002539 0.895119 ( 0.897642) 16480 ```
This commit is contained in:
parent
ad03320743
commit
a182b2c5e1
16
enumerator.c
16
enumerator.c
@ -256,23 +256,15 @@ struct enum_product {
|
|||||||
|
|
||||||
VALUE rb_cArithSeq;
|
VALUE rb_cArithSeq;
|
||||||
|
|
||||||
#define enumerator_free RUBY_TYPED_DEFAULT_FREE
|
|
||||||
|
|
||||||
static size_t
|
|
||||||
enumerator_memsize(const void *p)
|
|
||||||
{
|
|
||||||
return sizeof(struct enumerator);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const rb_data_type_t enumerator_data_type = {
|
static const rb_data_type_t enumerator_data_type = {
|
||||||
"enumerator",
|
"enumerator",
|
||||||
{
|
{
|
||||||
REFS_LIST_PTR(enumerator_refs),
|
REFS_LIST_PTR(enumerator_refs),
|
||||||
enumerator_free,
|
RUBY_TYPED_DEFAULT_FREE,
|
||||||
enumerator_memsize,
|
NULL, // Nothing allocated externally, so don't need a memsize function
|
||||||
NULL,
|
NULL,
|
||||||
},
|
},
|
||||||
0, NULL, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_DECL_MARKING
|
0, NULL, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_DECL_MARKING | RUBY_TYPED_EMBEDDABLE
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct enumerator *
|
static struct enumerator *
|
||||||
@ -1909,7 +1901,7 @@ lazy_add_method(VALUE obj, int argc, VALUE *argv, VALUE args, VALUE memo,
|
|||||||
rb_ary_push(new_procs, entry_obj);
|
rb_ary_push(new_procs, entry_obj);
|
||||||
|
|
||||||
new_obj = enumerator_init_copy(enumerator_allocate(rb_cLazy), obj);
|
new_obj = enumerator_init_copy(enumerator_allocate(rb_cLazy), obj);
|
||||||
new_e = DATA_PTR(new_obj);
|
new_e = RTYPEDDATA_GET_DATA(new_obj);
|
||||||
new_e->obj = new_generator;
|
new_e->obj = new_generator;
|
||||||
new_e->procs = new_procs;
|
new_e->procs = new_procs;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user