w_wad: optimize W_LumpExists

in two parts:
- Use our lumpcache lookup first (our unordered map), BUT since it is case insensitive we extract our lump out of it to do another case sensitive name compare
- In the manual lump seach falltthrough case, we can also check against the string lenghts and hash (its case insensitive but will still reject differing names, same with stringlenght)

this improves the performance of the leaderboard map browser quite a bit and everything else using v.patchExists
This commit is contained in:
Alug committed 2025-12-05 14:51:58 +01:00
1 parent 370c1dcf8c
commit 1c33aaec3d
1 file changed
+26 -1
+26 -1
View File
@@ -1412,13 +1412,38 @@ lumpnum_t W_CheckNumForNameInBlock(const char *name, const char *blockstart, con
UINT8 W_LumpExists(const char *name)
{
INT32 i, j;
UINT32 hash;
size_t namelen;
lumpnum_t cachenum = CheckLumpInCache(name);
if (cachenum != LUMPERROR)
{
// ok ok, we did find a lump in our lumpcache BUTT
// the lumpcache map is case insensitive
// extract the lumpinfo out of the lumpnum
// so we can do one more extra case ~sensitive~ name compare
// otherwise we gotta fall through to our manual lump search below
// lumpnum == (i << 16) | check
UINT16 wadnum = (cachenum >> 16) & 0xFFFF;
UINT16 lumpid = cachenum & 0xFFFF;
lumpinfo_t *lump_p = &wadfiles[wadnum]->lumpinfo[lumpid];
if (fastcmp(lump_p->name, name))
return true;
}
namelen = strlen(name);
hash = W_HashLumpName(name);
for (i = numwadfiles - 1; i >= 0; i--)
{
lumpinfo_t *lump_p = wadfiles[i]->lumpinfo;
for (j = 0; j < wadfiles[i]->numlumps; ++j, ++lump_p)
if (fastcmp(lump_p->name, name))
{
if (lump_p->namelength == namelen
&& lump_p->hash.name == hash
&& fastcmp(lump_p->name, name))
return true;
}
}
return false;