No computing embed_capa_max in ary_make_partial
ary_make_partial now uses the actual embed_capa of an allocated heap array to guide whether make an embedded copy or a slice view.
This commit is contained in:
parent
5336b2f0db
commit
aeff31168a
Notes:
git
2023-08-03 12:34:43 +00:00
9
array.c
9
array.c
@ -1194,10 +1194,10 @@ ary_make_partial(VALUE ary, VALUE klass, long offset, long len)
|
|||||||
assert(len >= 0);
|
assert(len >= 0);
|
||||||
assert(offset+len <= RARRAY_LEN(ary));
|
assert(offset+len <= RARRAY_LEN(ary));
|
||||||
|
|
||||||
const size_t rarray_embed_capa_max = (sizeof(struct RArray) - offsetof(struct RArray, as.ary)) / sizeof(VALUE);
|
VALUE result = ary_alloc_heap(klass);
|
||||||
|
size_t embed_capa = ary_embed_capa(result);
|
||||||
if ((size_t)len <= rarray_embed_capa_max && ary_embeddable_p(len)) {
|
if ((size_t)len <= embed_capa) {
|
||||||
VALUE result = ary_alloc_embed(klass, len);
|
FL_SET_EMBED(result);
|
||||||
ary_memcpy(result, 0, len, RARRAY_CONST_PTR(ary) + offset);
|
ary_memcpy(result, 0, len, RARRAY_CONST_PTR(ary) + offset);
|
||||||
ARY_SET_EMBED_LEN(result, len);
|
ARY_SET_EMBED_LEN(result, len);
|
||||||
return result;
|
return result;
|
||||||
@ -1205,7 +1205,6 @@ ary_make_partial(VALUE ary, VALUE klass, long offset, long len)
|
|||||||
else {
|
else {
|
||||||
VALUE shared = ary_make_shared(ary);
|
VALUE shared = ary_make_shared(ary);
|
||||||
|
|
||||||
VALUE result = ary_alloc_heap(klass);
|
|
||||||
assert(!ARY_EMBED_P(result));
|
assert(!ARY_EMBED_P(result));
|
||||||
|
|
||||||
ARY_SET_PTR(result, RARRAY_CONST_PTR(ary));
|
ARY_SET_PTR(result, RARRAY_CONST_PTR(ary));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user