From ead56b83e3da2e19e9edf84b793890d4e3994022 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Feb 2026 01:06:15 +0100 Subject: [PATCH] luaS_newlstr: use hash also for checking strings taken from raptorjit we can check the hash first to skip quite a bunch of memcmps which should be faster in most cases (hopefully but quick timedemo tests confirmed that) --- src/blua/lstring.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/blua/lstring.c b/src/blua/lstring.c index a5be75cc5..32ef78fb8 100644 --- a/src/blua/lstring.c +++ b/src/blua/lstring.c @@ -90,9 +90,7 @@ static unsigned hash_sparse(const char *str, size_t len) { /* Constants taken from lookup3 hash by Bob Jenkins. */ unsigned int a, b, h = cast(unsigned int, len); - if (len == 0) return 0; - #define rol(x, n) (((x)<<(n)) | ((x)>>(-cast(int, n)&(8*sizeof(x)-1)))) if (len >= 4) { /* Caveat: unaligned access! */ a = getu32(str); @@ -136,7 +134,9 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { o != NULL; o = o->gch.next) { TString *ts = rawgco2ts(o); - if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { + if (ts->tsv.hash == h && + ts->tsv.len == l && + (memcmp(str, getstr(ts), l) == 0)) { /* string may be dead */ if (isdead(G(L), o)) changewhite(o); return ts;