From 780b968bc76359f464d9908e073f647cb8c28ba0 Mon Sep 17 00:00:00 2001 From: Amos Date: Tue, 11 Oct 2022 16:31:00 +0200 Subject: [PATCH] CPackedStore::GetDirectoryFile optimizations Break when we have a locale, or found the context. Removed extraneous logic/vars. --- r5dev/vpklib/packedstore.cpp | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/r5dev/vpklib/packedstore.cpp b/r5dev/vpklib/packedstore.cpp index 7feb59cd..7d69bfc4 100644 --- a/r5dev/vpklib/packedstore.cpp +++ b/r5dev/vpklib/packedstore.cpp @@ -63,47 +63,35 @@ VPKDir_t CPackedStore::GetDirectoryFile(string svPackDirFile, bool bSanitizeName StringReplace(svPackDirFile, smRegexMatches[0], "pak000_dir"); bool bHasLocale = false; - bool bHasContext = false; string svPackDirPrefix; - size_t nLocaleIndex = 0; // Default to ENGLISH; - size_t nContextIndex = 0; // Default to SERVER; - for (size_t i = 0, nl = DIR_LOCALE.size(); i < nl; i++) { const string& svLocale = DIR_LOCALE[i]; if (svPackDirFile.find(svLocale) != string::npos) { - svPackDirPrefix.append(svLocale); - nLocaleIndex = i; bHasLocale = true; + break; } } - if (svPackDirPrefix.empty()) // No locale found. - { - svPackDirPrefix.append(DIR_LOCALE[0]); - } - if (!bHasLocale) { + svPackDirPrefix.append(DIR_LOCALE[0]); + for (size_t i = 0, nc = DIR_CONTEXT.size(); i < nc; i++) { const string& svContext = DIR_CONTEXT[i]; if (svPackDirFile.find(svContext) != string::npos) { svPackDirPrefix.append(svContext); - nContextIndex = i; - bHasContext = true; + StringReplace(svPackDirFile, svContext, svPackDirPrefix); + + break; } } } - if (bHasContext) // Context is required for this to work. - { - StringReplace(svPackDirFile, DIR_CONTEXT[nContextIndex], svPackDirPrefix); - } - return VPKDir_t(svPackDirFile); }