Commit 1ed7a764
1ed7a764a8bbMerged
Ryan Seys <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
fix(runtime): flatten(n) unboxes float sub-arrays
The depth-bounded Array#flatten(n) walker expanded int, string, and poly
sub-arrays but fell through on a float sub-array, leaving it boxed and opaque --
[[1.5, 2.5], [3.5]].flatten(1) returned [[1.5, 2.5], [3.5]] instead of
[1.5, 2.5, 3.5]. Add the float-array case so the bounded variant matches the
unbounded flatten.
Details
- Commit
- 1ed7a764a8bb
- Parent
- 6c31935943d9
lib/sp_runtime.hmodifiedView file
@@ -3818,6 +3818,7 @@
38183818
if (depth == 0 || v.tag != SP_TAG_OBJ) { sp_PolyArray_push(dst, v); return; }38193819
if (v.cls_id == SP_BUILTIN_INT_ARRAY) { sp_IntArray *ia = (sp_IntArray *)v.v.p; for (mrb_int i = 0; i < ia->len; i++) sp_PolyArray_push(dst, sp_box_int(ia->data[ia->start + i])); return; }38203820
if (v.cls_id == SP_BUILTIN_STR_ARRAY) { sp_StrArray *sa = (sp_StrArray *)v.v.p; for (mrb_int i = 0; i < sa->len; i++) sp_PolyArray_push(dst, sp_box_str(sa->data[i])); return; }3821+
if (v.cls_id == SP_BUILTIN_FLT_ARRAY) { sp_FloatArray *fa = (sp_FloatArray *)v.v.p; for (mrb_int i = 0; i < fa->len; i++) sp_PolyArray_push(dst, sp_box_float(fa->data[i])); return; }38213822
if (v.cls_id == SP_BUILTIN_POLY_ARRAY) { sp_PolyArray *pa = (sp_PolyArray *)v.v.p; for (mrb_int i = 0; i < pa->len; i++) sp_PolyArray_flatten_into_n(dst, pa->data[i], depth - 1); return; }38223823
sp_PolyArray_push(dst, v);38233824
}test/range_overlap_array_flatten_depth.rbmodifiedView file
Loading diff…
test/range_overlap_array_flatten_depth.rb.expectedmodifiedView file
Loading diff…