musicdef_t: Add hash field

Slight optimisation for S_FindMusicDef, but will net us some big wins with our next feature.
This commit is contained in:
toaster 2023-03-22 23:34:01 +00:00
parent 7868f21dd0
commit cb4d9b527e
2 changed files with 11 additions and 7 deletions

View file

@ -1368,16 +1368,18 @@ struct cursongcredit cursongcredit; // Currently displayed song credit info
// //
musicdef_t *S_FindMusicDef(const char *name) musicdef_t *S_FindMusicDef(const char *name)
{ {
musicdef_t *def = musicdefstart; UINT32 hash = quickncasehash (name, 6);
musicdef_t *def;
while (def) for (def = musicdefstart; def; def = def->next)
{ {
if (!stricmp(def->name, name)) if (hash != def->hash)
{ continue;
return def;
}
def = def->next; if (stricmp(def->name, name))
continue;
return def;
} }
return NULL; return NULL;
@ -1439,6 +1441,7 @@ ReadMusicDefFields
STRBUFCPY(def->name, value); STRBUFCPY(def->name, value);
strlwr(def->name); strlwr(def->name);
def->hash = quickncasehash (def->name, 6);
def->volume = DEFAULT_MUSICDEF_VOLUME; def->volume = DEFAULT_MUSICDEF_VOLUME;
def->next = musicdefstart; def->next = musicdefstart;

View file

@ -178,6 +178,7 @@ boolean S_SpeedMusic(float speed);
struct musicdef_t struct musicdef_t
{ {
char name[7]; char name[7];
UINT32 hash;
char *title; char *title;
char *author; char *author;
char *source; char *source;