From 68851c357a827889a7ed18085453fd78fe39dbef Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 9 Jun 2026 09:30:54 +0200 Subject: [PATCH] simplify W_CheckNumForNamePwad pretty much what blankart does avoids doing a bunch of string work --- src/w_wad.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 1099667e0..ba258176e 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -395,6 +395,11 @@ FUNCINLINE static ATTRINLINE UINT32 W_HashLumpName(const char *name) return FNV1a_HashLowercaseString(name); } +FUNCINLINE static ATTRINLINE UINT32 W_HashLumpNameLen(const char *name, size_t len) +{ + return FNV1a_QuickCaseHash(name, len); +} + /** Detect a file type. * \todo Actually detect the wad/pkzip headers and whatnot, instead of just checking the extensions. */ @@ -1094,18 +1099,15 @@ const char *W_CheckNameForNum(lumpnum_t lumpnum) UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) { UINT16 i; - static char uname[8 + 1]; UINT32 hash; size_t namelen; if (!TestValidLump(wad, 0)) return INT16_MAX; - memset(uname, 0, sizeof(uname)); - strncpy(uname, name, sizeof(uname)-1); - strupr(uname); - namelen = strlen(uname); - hash = W_HashLumpName(uname); + namelen = strlen(name); + namelen = min(namelen, 8); // :chaosleep: + hash = W_HashLumpNameLen(name, namelen); // // scan forward @@ -1120,7 +1122,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) { if (lump_p->namelength == namelen && lump_p->hash.name == hash - && !memcmp(lump_p->name, uname, sizeof(uname) - 1)) + && !strncasecmp(lump_p->name, name, namelen)) return i; } }