From 60ab485b2968c6499f496352fc4d28e80ab3d130 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Fri, 9 May 2025 11:17:22 +0100 Subject: [PATCH] Comments. --- sqlite3/libc/libc.wasm | Bin 5536 -> 5636 bytes sqlite3/libc/libc.wat | 1378 +++++++++++++++++++++------------------- sqlite3/libc/string.h | 69 +- 3 files changed, 790 insertions(+), 657 deletions(-) diff --git a/sqlite3/libc/libc.wasm b/sqlite3/libc/libc.wasm index 9d2dab0530d96f35f707239367b44cd71cf91cc4..f2f37223e1f63b817318cc255307e723ce644b3f 100755 GIT binary patch delta 1317 zcmZ`(!HN_y5KYoa_w;n9yJyA2xR>e(UQ`5+A~;!Dmvx!lgBMSNAfnwD2fcY{1rhWl z%nyh+FCy$Wc=Uff81*GR?##~4HWZyoRlQVI>gDs*ch|m8xcG79c!&Q=yN{Vjy1{GW z6z$82Wo0HNUTMw1mIoBs>S(qrC&cbBTfM@*EnAaLu_IvQt%)0#Fji+I!e5iHys49D z0-TH(MGd?hW6WJ9O{`zJLsPg1yP7?w!aXq(s|aV1eAXC+cuFX)*sfM25lwPtq-I%$ z#JH_mqZX-BMCzc=npDjRDK>^tI)yWQqqZJo^9$9@ZZOp%ml^zl*BH4M&`_-XM7HY- zNhq;@_P&UpTCaJA`!ihr5;g9*?gwQcTcJaaWVic{nQ#xyoQqmoS%B!oyHlg;iPLg z!!?}D<2aq`!r$o0x9D{FztbVdoS^e%j@s+DSBfqC#!9gz?kBGRx+?umON??Y=WmNk z^Do7?D>nNTqyiuOyr(q0r#W~?VJ0JrTPxarJg&2TAk;0~h^GLC7CZx!Y`5UT27V_e z)b3Wf9iQbk*nFDZRbV#;XcM_HyPn+gG`TIS6@lOwtc#^@qE8xpmaXB>_qBi}@;?-C whUAFl5niuaiV5f-;DYGjivONQ=nC@*#K&8KF0lSk|0Zz4Bf+xcN7at{2Th0wN&o-= delta 1165 zcmbVMJ&P1U5bdw|?%tUV7IZJEZZT33%rtT5;9TT5FEBCFKty&E56lea0y!`f<_Bmb zn22z~<^B`@g@KK}nmcdT^-LTnx~seT^{cLW^ZNSxYoBLQeY<+REx#Athf<|o{)!~& z`)1aPx>7SWBi+_}W=7(!Xq%U$mu<5Q=`L2JH&#`oNH1EsjF}L=BsGi{r_|DCq*}S~ zxn`V_#95>eB3>a&A`Y|oAh`H&r*nc_d>YJ-6B_rCdAzPWCkp=ft?K4-3lz-0MAar^P=PzI{z*N&o{t}0eppB zZeUlZ*w*!5Mw7>*->)_hwFH0d5ghw#k1%3??Gb7kN85nky2VctwKC`#Z~C^Lb|~=r zKF>L(Mwec=;V9vLOwey=zU-cpERJk}!fVQwEC?=tazhLS=WaB(j~nq0>d38*Q10 sh) return NULL; haystk += skip; } @@ -506,16 +526,31 @@ static const char *__memmem_rabin(const char *haystk, size_t sh, static const char *__memmem_raita(const char *haystk, size_t sh, const char *needle, size_t sn) { // https://www-igm.univ-mlv.fr/~lecroq/string/node22.html + + // We've handled empty and single character needles. + // The needle is no longer than haystack. __builtin_assume(2 <= sn && sn <= sh); + // Compute Boyer-Moore's bad-character shift function. + // Only the last 255 characters of the needle matter for shifts up to 255, + // which is good enough for most needles. + size_t n = sn - 1; + size_t i = 0; + int c = n; + if (c >= 255) { + c = 255; + i = n - 255; + } + #ifndef _REENTRANT static #endif uint8_t bmbc[256]; - memset(bmbc, sn - 1 < 255 ? sn - 1 : 255, sizeof(bmbc)); - for (size_t i = 0; i < sn - 1; i++) { - size_t t = sn - 1 - i - 1; - if (t > 255) t = 255; + memset(bmbc, c, sizeof(bmbc)); + for (; i < n; i++) { + // One less than the usual offset. + // Added back later (as vector). + size_t t = n - i - 1; bmbc[(unsigned char)needle[i]] = t; } @@ -527,8 +562,10 @@ static const char *__memmem(const char *haystk, size_t sh, // // Return when needle is longer than haystack. if (sn > sh) return NULL; - return sn < sizeof(v128_t) ? __memmem_rabin(haystk, sh, needle, sn, NULL) - : __memmem_raita(haystk, sh, needle, sn); + // Decide if Boyer-Moore's bad-character rule will be useful. + return sn < sizeof(v128_t) || sh - sn < sizeof(v128_t) + ? __memmem_rabin(haystk, sh, needle, sn, NULL) + : __memmem_raita(haystk, sh, needle, sn); } __attribute__((weak))