Skip to content

Commit

Permalink
Let empty arrays being flattened not alloc additional state
Browse files Browse the repository at this point in the history
  • Loading branch information
methodmissing authored and hsbt committed Oct 25, 2023
1 parent a6a67b0 commit cd18b09
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -6306,6 +6306,12 @@ flatten(VALUE ary, int level)
st_table *memo = 0;
st_data_t id;

if (UNLIKELY(RARRAY_LEN(ary) == 0)) {
result = ary_new(0, 0);
RBASIC_SET_CLASS(result, rb_obj_class(ary));
return result;
}

for (i = 0; i < RARRAY_LEN(ary); i++) {
elt = RARRAY_AREF(ary, i);
tmp = rb_check_array_type(elt);
Expand Down

0 comments on commit cd18b09

Please sign in to comment.