From 9b800a19f73321a33b5eef340ea8ab5899b54bcb Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 7 Feb 2024 14:30:37 +0100 Subject: [PATCH] Tier1: optimize V_UnqualifiedFileName() If we are going to do a strlen, then check the chars from the start --- src/tier1/strtools.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/tier1/strtools.cpp b/src/tier1/strtools.cpp index 4e7b5527..0aed46ae 100644 --- a/src/tier1/strtools.cpp +++ b/src/tier1/strtools.cpp @@ -1105,14 +1105,21 @@ size_t V_StripLastDir(char* dirName, size_t maxLen) //----------------------------------------------------------------------------- const char* V_UnqualifiedFileName(const char* in) { - if (!in || !in[0]) - return in; + Assert(in); + + const char* out = in; + + while (*in) + { + if (PATHSEPARATOR(*in)) + { + // +1 to skip the slash + out = in + 1;; + } + + in++; + } - // back up until the character after the first path separator we find, - // or the beginning of the string - const char* out = in + strlen(in) - 1; - while ((out > in) && (!PATHSEPARATOR(*(out - 1)))) - out--; return out; }