diff --git a/src/builtins/search.c b/src/builtins/search.c index eaf79b29..2a691c39 100644 --- a/src/builtins/search.c +++ b/src/builtins/search.c @@ -132,6 +132,38 @@ static B reduceI32Width(B r, usz count) { return count<=I8_MAX? taga(cpyI8Arr(r)) : count<=I16_MAX? taga(cpyI16Arr(r)) : r; } +static NOINLINE usz indexOfOne(B l, B e) { + void* lp = tyany_ptr(l); + usz wia = IA(l); + u8 v8; u16 v16; u32 v32; f64 v64f; + switch(TI(l,elType)) { default: UD; + case el_bit: if (!q_bit(e)) return wia; return bit_find(lp,wia,o2bG(e)); + case el_i8: if (!q_i8 (e)) return wia; v8 = ( u8)( i8)o2iG(e); goto chk8; + case el_i16: if (!q_i16(e)) return wia; v16 = (u16)(i16)o2iG(e); goto chk16; + case el_i32: if (!q_i32(e)) return wia; v32 = (u32)(i32)o2iG(e); goto chk32; + case el_f64: if (!q_f64(e)) return wia; v64f= o2fG(e); goto chk64f; + case el_c8: if (!q_c8 (e)) return wia; v8 = ( u8) o2cG(e); goto chk8; + case el_c16: if (!q_c16(e)) return wia; v16 = (u16) o2cG(e); goto chk16; + case el_c32: if (!q_c32(e)) return wia; v32 = (u32) o2cG(e); goto chk32; + case el_B: { + if (isF64(e) && sizeof(B)==sizeof(f64)) { // TODO could also have character atom case + if ((lp = arr_bptr(l)) == NULL) goto generic; + v64f = o2fG(e); + goto chk64f; + } + generic:; + SGetU(l) + for (usz i = 0; i < wia; i++) if (equal(GetU(l,i), e)) return i; + return wia; + } + } + + chk8: for (ux i=0; i