Commit 1a60cc65
1a60cc65c07dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Equality between a poly array and a typed array
A compact/poly result compared against a typed-array literal (e.g. [1,nil,2].compact == [1,2]) mixed sp_PolyArray * and sp_IntArray * and failed the -Werror build. The new sp_PolyArray_eq_typed boxes the typed side element-wise and compares via sp_PolyArray_eq; codegen dispatches it for either operand order.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 1a60cc65c07d
- Parent
- eee34c2109f8
lib/sp_runtime.hmodifiedView file
@@ -3255,6 +3255,25 @@
32553255
}32563256
return TRUE;32573257
}3258+
/* Compare a poly array against a typed (int/str/float) array by boxing the3259+
typed side element-wise. `kind` is the typed array's SP_BUILTIN_* tag. */3260+
static mrb_bool sp_PolyArray_eq_typed(sp_PolyArray *pa, void *tp, int kind) {3261+
if (!pa || !tp) return FALSE;3262+
sp_PolyArray *tb = sp_PolyArray_new();3263+
if (kind == SP_BUILTIN_STR_ARRAY) {3264+
sp_StrArray *a = (sp_StrArray *)tp;3265+
for (mrb_int i = 0; i < a->len; i++) sp_PolyArray_push(tb, sp_box_str(sp_StrArray_get(a, i)));3266+
}3267+
else if (kind == SP_BUILTIN_FLT_ARRAY) {3268+
sp_FloatArray *a = (sp_FloatArray *)tp;3269+
for (mrb_int i = 0; i < a->len; i++) sp_PolyArray_push(tb, sp_box_float(sp_FloatArray_get(a, i)));3270+
}3271+
else {3272+
sp_IntArray *a = (sp_IntArray *)tp;3273+
for (mrb_int i = 0; i < a->len; i++) sp_PolyArray_push(tb, sp_box_int(sp_IntArray_get(a, i)));3274+
}3275+
return sp_PolyArray_eq(pa, tb);3276+
}32583277
static mrb_bool sp_PolyArray_include(sp_PolyArray *a, sp_RbVal v) {32593278
if (!a) return FALSE;32603279
for (mrb_int i = 0; i < a->len; i++) {src/codegen.cmodifiedView file
Loading diff…