From ea0aa709fe65b17f02f559de1a16ebdd76d8785c Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 27 Jan 2023 02:56:56 +0200 Subject: [PATCH] =?UTF-8?q?squeeze=20result=20of=20=E2=8A=92=F0=9D=95=A9,?= =?UTF-8?q?=20copy=20result=20of=20=E2=8A=90=F0=9D=95=A9=20to=20smaller=20?= =?UTF-8?q?width=20when=20possible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/search.c | 8 ++++---- src/builtins/selfsearch.c | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/builtins/search.c b/src/builtins/search.c index ba6da416..0a2847e7 100644 --- a/src/builtins/search.c +++ b/src/builtins/search.c @@ -61,7 +61,7 @@ static NOINLINE B2 splitCells(B n, B p, u8 mode) { // 0:∊ 1:⊐ 2:⊒ #undef SYMB } -static B reduceWidth(B r, usz count) { +static B reduceI32Width(B r, usz count) { return count<=I8_MAX? taga(cpyI8Arr(r)) : count<=I16_MAX? taga(cpyI16Arr(r)) : r; } @@ -127,7 +127,7 @@ B indexOf_c2(B t, B w, B x) { if (xia+wia>20 && we<=el_i16 && xe<=el_i16) { B r; TABLE(w, x, i32, wia, i) - return reduceWidth(r, wia); + return reduceI32Width(r, wia); } i32* rp; B r = m_i32arrc(&rp, x); H_b2i* map = m_b2i(64); @@ -139,7 +139,7 @@ B indexOf_c2(B t, B w, B x) { } for (usz i = 0; i < xia; i++) rp[i] = getD_b2i(map, GetU(x,i), wia); free_b2i(map); decG(w); decG(x); - return reduceWidth(r, wia); + return reduceI32Width(r, wia); } } @@ -266,7 +266,7 @@ B count_c2(B t, B w, B x) { free_b2i(map); } TFREE(wnext); decG(w); decG(x); - return reduceWidth(r, wia); + return reduceI32Width(r, wia); } diff --git a/src/builtins/selfsearch.c b/src/builtins/selfsearch.c index 32c77dd0..36dffb61 100644 --- a/src/builtins/selfsearch.c +++ b/src/builtins/selfsearch.c @@ -244,7 +244,7 @@ B memberOf_c1(B t, B x) { else for (usz j=0; ja[p].val : (map->a[p].val = 0); } decG(x); free_b2i(map); - return r; + return num_squeeze(r); +} + +static B reduceI32WidthBelow(B r, usz after) { + return after<=2? taga(cpyBitArr(r)) : after<=I8_MAX+1? taga(cpyI8Arr(r)) : after<=I16_MAX+1? taga(cpyI16Arr(r)) : r; } B indexOf_c1(B t, B x) { @@ -431,7 +435,7 @@ B indexOf_c1(B t, B x) { rp[i]=s; u+=u==s; \ } \ decG(x); TFREE(uniq); return r; - #define DOTAB(T) \ + #define DOTAB(T) /*leaves 1+max in u */ \ i32 u=0; \ for (usz i=0; i=(1<<18)? 1 : sz>=(1<<14)? 4 : 6) decG(r); // Fall through @@ -503,7 +507,7 @@ B indexOf_c1(B t, B x) { else rp[i] = map->a[p].val = ctr++; } free_b2i(map); decG(x); - return r; + return reduceI32WidthBelow(r, ctr); } B find_c1(B t, B x) {