From 9494ef7b9f0acc813d300a501542ff34fc40bc43 Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 17 Sep 2021 15:12:23 +0300 Subject: [PATCH] don't keep fl_squoze of not actually guaranteed full squeeze --- src/core/fillarr.c | 2 ++ src/core/stuff.c | 8 ++++++-- src/core/stuff.h | 10 +++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/core/fillarr.c b/src/core/fillarr.c index 407a2b91..9d0ece47 100644 --- a/src/core/fillarr.c +++ b/src/core/fillarr.c @@ -126,9 +126,11 @@ B withFill(B x, B fill) { // consumes both if (isNum(fill)) { x = num_squeezeChk(x); if (elNum(TI(x,elType))) return x; + FL_KEEP(x, ~fl_squoze); } else if (isC32(fill)) { x = chr_squeezeChk(x); if (elChr(TI(x,elType))) return x; + FL_KEEP(x, ~fl_squoze); } FillArr* r = m_arr(fsizeof(FillArr,a,B,ia), t_fillarr, ia); arr_shCopy((Arr*)r, x); diff --git a/src/core/stuff.c b/src/core/stuff.c index db1de84b..fb97266b 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -200,7 +200,11 @@ NOINLINE B do_fmt(B s, char* p, va_list a) { AFMT("%f", o2f(b)); } else { assert(isArr(b) && rnk(b)==1); if (TI(b,elType)==el_c32) AJOIN(inc(b)); - else AJOIN(chr_squeezeChk(inc(b))); + else { + B sq = chr_squeezeChk(b); + if (!elChr(TI(sq,elType))) FL_KEEP(sq, ~fl_squoze); + AJOIN(inc(sq)); + } } break; } @@ -566,7 +570,7 @@ B any_squeeze(B x) { B x0 = GetU(x, 0); if (isNum(x0)) return num_squeeze(x); else if (isC32(x0)) return chr_squeeze(x); - return x; + return FL_SET(x, fl_squoze); } B squeeze_deep(B x) { diff --git a/src/core/stuff.h b/src/core/stuff.h index 403fcbad..05d53d47 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -137,10 +137,14 @@ char* format_pm1(u8 u); char* format_pm2(u8 u); bool isPureFn(B x); // doesn't consume B bqn_merge(B x); // consumes + B any_squeeze(B x); // consumes; accepts any array, returns one with the smallest type (doesn't recurse!) -B num_squeeze(B x); // consumes; accepts any array, but only tries to squeeze numerical values; doesn't check for fl_squoze -B chr_squeeze(B x); // consumes; accepts any array, but only tries to squeeze character values; doesn't check for fl_squoze -B squeeze_deep(B x); // consumes; accepts any object, returns an object with all hashable parts squeezed +B squeeze_deep(B x); // consumes; accepts any object, returns an object with all parts necessary for equality checking & hashing squeezed +B num_squeeze(B x); // consumes; see note below +B chr_squeeze(B x); // consumes; see note below +// Note that num_squeeze & chr_squeeze don't check for fl_squoze, and unconditionally set it. Thus, don't call it on an array if it could be squeezable by the opposite method. +// or, if you do want to, if TI(x,elType) isn't of the squeezed type, either remove fl_squoze or call the other squeeze function. +// The functions below can be used as direct replacements of (num|chr)_squeeze if the argument might already be squeezed. static inline B num_squeezeChk(B x) { return FL_HAS(x,fl_squoze)? x : num_squeeze(x); } static inline B chr_squeezeChk(B x) { return FL_HAS(x,fl_squoze)? x : chr_squeeze(x); } B def_fn_uc1(B t, B o, B x);