From 0bfbc51838459937289ef1ff55c3bf24515b315f Mon Sep 17 00:00:00 2001 From: Steam Deck User Date: Thu, 16 Mar 2023 17:43:00 -0400 Subject: [PATCH] Stop using Q_strcmp, trust that the standard strcmp is faster --- source/cmd.c | 4 ++-- source/common.c | 19 ++----------------- source/common.h | 1 - source/cvar.c | 4 ++-- source/host_cmd.c | 6 +++--- source/menu.c | 4 ++-- source/net_dgrm.c | 6 +++--- source/net_loop.c | 4 ++-- source/psp/main.cpp | 2 +- source/psp/network_infrastructure.cpp | 2 +- source/psp/network_psp.cpp | 4 ++-- source/psp/video_hardware_model.cpp | 20 ++++++++++---------- source/snd_dma.c | 2 +- 13 files changed, 31 insertions(+), 47 deletions(-) diff --git a/source/cmd.c b/source/cmd.c index e1355ab..751f211 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -713,7 +713,7 @@ void Cmd_AddCommand (char *cmd_name, xcommand_t function) // fail if the command already exists for (cmd=cmd_functions ; cmd ; cmd=cmd->next) { - if (!Q_strcmp (cmd_name, cmd->name)) + if (!strcmp (cmd_name, cmd->name)) { Con_Printf ("Cmd_AddCommand: %s already defined\n", cmd_name); return; @@ -738,7 +738,7 @@ qboolean Cmd_Exists (char *cmd_name) for (cmd=cmd_functions ; cmd ; cmd=cmd->next) { - if (!Q_strcmp (cmd_name,cmd->name)) + if (!strcmp (cmd_name,cmd->name)) return true; } diff --git a/source/common.c b/source/common.c index 57d5365..9701217 100644 --- a/source/common.c +++ b/source/common.c @@ -207,21 +207,6 @@ void Q_strcat (char *dest, char *src) Q_strcpy (dest, src); } -int Q_strcmp (char *s1, char *s2) -{ - while (1) - { - if (*s1 != *s2) - return -1; // strings not equal - if (!*s1) - return 0; // strings are equal - s1++; - s2++; - } - - return -1; -} - int Q_strncmp (char *s1, char *s2, int count) { while (1) @@ -1083,7 +1068,7 @@ int COM_CheckParm (char *parm) { if (!com_argv[i]) continue; // NEXTSTEP sometimes clears appkit vars. - if (!Q_strcmp (parm,com_argv[i])) + if (!strcmp (parm,com_argv[i])) return i; } @@ -1129,7 +1114,7 @@ void COM_InitArgv (int argc, char **argv) com_argc++) { largv[com_argc] = argv[com_argc]; - if (!Q_strcmp ("-safe", argv[com_argc])) + if (!strcmp ("-safe", argv[com_argc])) safe = true; } diff --git a/source/common.h b/source/common.h index 978865a..b965b70 100644 --- a/source/common.h +++ b/source/common.h @@ -149,7 +149,6 @@ void Q_strncpy (char *dest, char *src, int count); int Q_strlen (char *str); char *Q_strrchr (char *s, char c); void Q_strcat (char *dest, char *src); -int Q_strcmp (char *s1, char *s2); int Q_strncmp (char *s1, char *s2, int count); int Q_strcasecmp (char *s1, char *s2); int Q_strncasecmp (char *s1, char *s2, int n); diff --git a/source/cvar.c b/source/cvar.c index 293b0c0..e5c2b8a 100644 --- a/source/cvar.c +++ b/source/cvar.c @@ -34,7 +34,7 @@ cvar_t *Cvar_FindVar (char *var_name) cvar_t *var; for (var=cvar_vars ; var ; var=var->next) - if (!Q_strcmp (var_name, var->name)) + if (!strcmp (var_name, var->name)) return var; return NULL; @@ -113,7 +113,7 @@ void Cvar_Set (char *var_name, char *value) return; } - changed = Q_strcmp(var->string, value); + changed = strcmp(var->string, value); Z_Free (var->string); // free the old value string diff --git a/source/host_cmd.c b/source/host_cmd.c index 93d905c..faf561e 100644 --- a/source/host_cmd.c +++ b/source/host_cmd.c @@ -682,7 +682,7 @@ void Host_Name_f (void) if (cmd_source == src_command) { - if (Q_strcmp(cl_name.string, newName) == 0) + if (strcmp(cl_name.string, newName) == 0) return; Cvar_Set ("_cl_name", newName); if (cls.state == ca_connected) @@ -691,7 +691,7 @@ void Host_Name_f (void) } if (host_client->name[0] && strcmp(host_client->name, "unconnected") ) - if (Q_strcmp(host_client->name, newName) != 0) + if (strcmp(host_client->name, newName) != 0) Con_Printf ("%s renamed to %s\n", host_client->name, newName); Q_strcpy (host_client->name, newName); host_client->edict->v.netname = host_client->name - pr_strings; @@ -1103,7 +1103,7 @@ void Host_Kick_f (void) save = host_client; - if (Cmd_Argc() > 2 && Q_strcmp(Cmd_Argv(1), "#") == 0) + if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0) { i = Q_atof(Cmd_Argv(2)) - 1; if (i < 0 || i >= svs.maxclients) diff --git a/source/menu.c b/source/menu.c index 2b0f676..0bbd6af 100644 --- a/source/menu.c +++ b/source/menu.c @@ -1927,9 +1927,9 @@ void M_Setup_Key (int k) // break; // setup_cursor == 4 (OK) - if (Q_strcmp(cl_name.string, setup_myname) != 0) + if (strcmp(cl_name.string, setup_myname) != 0) Cbuf_AddText ( va ("name \"%s\"\n", setup_myname) ); - if (Q_strcmp(hostname.string, setup_hostname) != 0) + if (strcmp(hostname.string, setup_hostname) != 0) Cvar_Set("hostname", setup_hostname); m_entersound = true; M_Menu_MultiPlayer_f (); diff --git a/source/net_dgrm.c b/source/net_dgrm.c index 8508c7a..8367c78 100644 --- a/source/net_dgrm.c +++ b/source/net_dgrm.c @@ -403,7 +403,7 @@ void NET_Stats_f (void) Con_Printf("shortPacketCount = %i\n", shortPacketCount); Con_Printf("droppedDatagrams = %i\n", droppedDatagrams); } - else if (Q_strcmp(Cmd_Argv(1), "*") == 0) + else if (strcmp(Cmd_Argv(1), "*") == 0) { for (s = net_activeSockets; s; s = s->next) PrintStats(s); @@ -781,7 +781,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void) command = MSG_ReadByte(); if (command == CCREQ_SERVER_INFO) { - if (Q_strcmp(MSG_ReadString(), "QUAKE") != 0) + if (strcmp(MSG_ReadString(), "QUAKE") != 0) return NULL; SZ_Clear(&net_message); @@ -884,7 +884,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void) if (command != CCREQ_CONNECT) return NULL; - if (Q_strcmp(MSG_ReadString(), "QUAKE") != 0) + if (strcmp(MSG_ReadString(), "QUAKE") != 0) return NULL; if (MSG_ReadByte() != NET_PROTOCOL_VERSION) diff --git a/source/net_loop.c b/source/net_loop.c index 35aa370..527edec 100644 --- a/source/net_loop.c +++ b/source/net_loop.c @@ -50,7 +50,7 @@ void Loop_SearchForHosts (qboolean xmit) return; hostCacheCount = 1; - if (Q_strcmp(hostname.string, "UNNAMED") == 0) + if (strcmp(hostname.string, "UNNAMED") == 0) Q_strcpy(hostcache[0].name, "local"); else Q_strcpy(hostcache[0].name, hostname.string); @@ -64,7 +64,7 @@ void Loop_SearchForHosts (qboolean xmit) qsocket_t *Loop_Connect (char *host) { - if (Q_strcmp(host,"local") != 0) + if (strcmp(host,"local") != 0) return NULL; localconnectpending = true; diff --git a/source/psp/main.cpp b/source/psp/main.cpp index 71a8d77..82e0bb1 100644 --- a/source/psp/main.cpp +++ b/source/psp/main.cpp @@ -185,7 +185,7 @@ int CheckParm (char **args, int argc, char *parm) { if (!args[i]) continue; // NEXTSTEP sometimes clears appkit vars. - if (!Q_strcmp (parm,args[i])) + if (!strcmp (parm,args[i])) return i; } diff --git a/source/psp/network_infrastructure.cpp b/source/psp/network_infrastructure.cpp index c971c89..c616388 100644 --- a/source/psp/network_infrastructure.cpp +++ b/source/psp/network_infrastructure.cpp @@ -132,7 +132,7 @@ namespace quake my_addr = inet_addr(szMyIPAddr); // if the quake hostname isn't set, set it to the machine name - if (Q_strcmp(hostname.string, "UNNAMED") == 0) + if (strcmp(hostname.string, "UNNAMED") == 0) { buff[15] = 0; Cvar_Set ("hostname", buff); diff --git a/source/psp/network_psp.cpp b/source/psp/network_psp.cpp index e528080..5546fca 100644 --- a/source/psp/network_psp.cpp +++ b/source/psp/network_psp.cpp @@ -173,7 +173,7 @@ namespace quake my_addr = inet_addr(szMyIPAddr); // if the quake hostname isn't set, set it to the machine name - if (Q_strcmp(hostname.string, "UNNAMED") == 0) + if (strcmp(hostname.string, "UNNAMED") == 0) { buff[15] = 0; Cvar_Set ("hostname", buff); @@ -652,7 +652,7 @@ namespace quake } gethostname(buff, MAXHOSTNAMELEN); - if (Q_strcmp(hostname.string, "UNNAMED") == 0) + if (strcmp(hostname.string, "UNNAMED") == 0) { buff[15] = 0; Cvar_Set ("hostname", buff); diff --git a/source/psp/video_hardware_model.cpp b/source/psp/video_hardware_model.cpp index 3120cf6..7a5fe82 100644 --- a/source/psp/video_hardware_model.cpp +++ b/source/psp/video_hardware_model.cpp @@ -2026,16 +2026,16 @@ void Mod_FloodFillSkin( byte *skin, int skinwidth, int skinheight ) qboolean model_is_zombie(char name[MAX_QPATH]) { - if (Q_strcmp(name, "models/ai/zb#.mdl") == 0 || - Q_strcmp(name, "models/ai/zbc#.mdl") == 0 || - Q_strcmp(name, "models/ai/zcfull.mdl") == 0 || - Q_strcmp(name, "models/ai/zhc^.mdl") == 0 || - Q_strcmp(name, "models/ai/zalc(.mdl") == 0 || - Q_strcmp(name, "models/ai/zarc(.mdl") == 0 || - Q_strcmp(name, "models/ai/zfull.mdl") == 0 || - Q_strcmp(name, "models/ai/zh^.mdl") == 0 || - Q_strcmp(name, "models/ai/zal(.mdl") == 0 || - Q_strcmp(name, "models/ai/zar(.mdl") == 0) + if (strcmp(name, "models/ai/zb#.mdl") == 0 || + strcmp(name, "models/ai/zbc#.mdl") == 0 || + strcmp(name, "models/ai/zcfull.mdl") == 0 || + strcmp(name, "models/ai/zhc^.mdl") == 0 || + strcmp(name, "models/ai/zalc(.mdl") == 0 || + strcmp(name, "models/ai/zarc(.mdl") == 0 || + strcmp(name, "models/ai/zfull.mdl") == 0 || + strcmp(name, "models/ai/zh^.mdl") == 0 || + strcmp(name, "models/ai/zal(.mdl") == 0 || + strcmp(name, "models/ai/zar(.mdl") == 0) return qtrue; return qfalse; diff --git a/source/snd_dma.c b/source/snd_dma.c index fc87811..da6bc32 100644 --- a/source/snd_dma.c +++ b/source/snd_dma.c @@ -285,7 +285,7 @@ sfx_t *S_FindName (char *name) // see if already loaded for (i=0 ; i < num_sfx ; i++) - if (!Q_strcmp(known_sfx[i].name, name)) + if (!strcmp(known_sfx[i].name, name)) { return &known_sfx[i]; }