From a865d423974ea06dffa47798c81e98e7570b02ec Mon Sep 17 00:00:00 2001 From: Alexander Gavriliuk Date: Tue, 5 Mar 2024 17:03:11 +0100 Subject: viewer#819 Avoid reading the same XML file multiple times --- indra/llfilesystem/lldir.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'indra/llfilesystem/lldir.cpp') diff --git a/indra/llfilesystem/lldir.cpp b/indra/llfilesystem/lldir.cpp index 69b23f9cf8..ee5dec2b77 100644 --- a/indra/llfilesystem/lldir.cpp +++ b/indra/llfilesystem/lldir.cpp @@ -71,6 +71,7 @@ LLDir *gDirUtilp = (LLDir *)&gDirUtil; /// Values for findSkinnedFilenames(subdir) parameter const char *LLDir::XUI = "xui", + *LLDir::HTML = "html", *LLDir::TEXTURES = "textures", *LLDir::SKINBASE = ""; @@ -761,14 +762,13 @@ std::vector LLDir::findSkinnedFilenames(const std::string& subdir, else { // We do not recognize this subdir. Investigate. - std::string subdir_path(add(getDefaultSkinDir(), subdir)); - if (fileExists(add(subdir_path, "en"))) + if (skinExists(subdir, "en")) { // defaultSkinDir/subdir contains subdir "en". That's our // default language; this subdir is localized. found = sLocalized.insert(StringMap::value_type(subdir, "en")).first; } - else if (fileExists(add(subdir_path, "en-us"))) + else if (skinExists(subdir, "en-us")) { // defaultSkinDir/subdir contains subdir "en-us" but not "en". // Set as default language; this subdir is localized. @@ -865,6 +865,33 @@ std::vector LLDir::findSkinnedFilenames(const std::string& subdir, return results; } +// virtual +bool LLDir::skinExists(const std::string& subdir, const std::string& skin) const +{ + std::string skin_path(add(getDefaultSkinDir(), subdir, skin)); + return fileExists(skin_path); +} + +// virtual +std::string LLDir::getFileContents(const std::string& filename) const +{ + LLFILE* fp = LLFile::fopen(filename, "rb"); /* Flawfinder: ignore */ + if (fp) + { + fseek(fp, 0, SEEK_END); + U32 length = ftell(fp); + fseek(fp, 0, SEEK_SET); + + std::vector buffer(length); + size_t nread = fread(buffer.data(), 1, length, fp); + fclose(fp); + + return std::string(buffer.data(), nread); + } + + return LLStringUtil::null; +} + std::string LLDir::getTempFilename() const { LLUUID random_uuid; -- cgit v1.2.3 From 2008f87f10d51a2f9372aa4a4d72e86ac94e1e81 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Mon, 13 May 2024 18:26:53 +0300 Subject: Revert "viewer#819 Avoid reading the same XML file multiple times" This reverts commit a865d423974ea06dffa47798c81e98e7570b02ec. Reason for revert: viewer#1420, reverting to not hold maint-A (is deepCopy not full?) --- indra/llfilesystem/lldir.cpp | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) (limited to 'indra/llfilesystem/lldir.cpp') diff --git a/indra/llfilesystem/lldir.cpp b/indra/llfilesystem/lldir.cpp index 0ba62fb698..41fbb97175 100644 --- a/indra/llfilesystem/lldir.cpp +++ b/indra/llfilesystem/lldir.cpp @@ -70,7 +70,6 @@ LLDir *gDirUtilp = (LLDir *)&gDirUtil; /// Values for findSkinnedFilenames(subdir) parameter const char *LLDir::XUI = "xui", - *LLDir::HTML = "html", *LLDir::TEXTURES = "textures", *LLDir::SKINBASE = ""; @@ -761,13 +760,14 @@ std::vector LLDir::findSkinnedFilenames(const std::string& subdir, else { // We do not recognize this subdir. Investigate. - if (skinExists(subdir, "en")) + std::string subdir_path(add(getDefaultSkinDir(), subdir)); + if (fileExists(add(subdir_path, "en"))) { // defaultSkinDir/subdir contains subdir "en". That's our // default language; this subdir is localized. found = sLocalized.insert(StringMap::value_type(subdir, "en")).first; } - else if (skinExists(subdir, "en-us")) + else if (fileExists(add(subdir_path, "en-us"))) { // defaultSkinDir/subdir contains subdir "en-us" but not "en". // Set as default language; this subdir is localized. @@ -864,33 +864,6 @@ std::vector LLDir::findSkinnedFilenames(const std::string& subdir, return results; } -// virtual -bool LLDir::skinExists(const std::string& subdir, const std::string& skin) const -{ - std::string skin_path(add(getDefaultSkinDir(), subdir, skin)); - return fileExists(skin_path); -} - -// virtual -std::string LLDir::getFileContents(const std::string& filename) const -{ - LLFILE* fp = LLFile::fopen(filename, "rb"); /* Flawfinder: ignore */ - if (fp) - { - fseek(fp, 0, SEEK_END); - U32 length = ftell(fp); - fseek(fp, 0, SEEK_SET); - - std::vector buffer(length); - size_t nread = fread(buffer.data(), 1, length, fp); - fclose(fp); - - return std::string(buffer.data(), nread); - } - - return LLStringUtil::null; -} - std::string LLDir::getTempFilename() const { LLUUID random_uuid; -- cgit v1.2.3 From b42f9d836b4c0f7fbd4bdae1734021e2a09fdbe8 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Sat, 1 Jun 2024 15:49:26 +0200 Subject: Re-enable a lot of compiler warnings for MSVC and address the C4267 "possible loss of precision" warnings --- indra/llfilesystem/lldir.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/llfilesystem/lldir.cpp') diff --git a/indra/llfilesystem/lldir.cpp b/indra/llfilesystem/lldir.cpp index cbf4c1ffb8..483ef0fd02 100644 --- a/indra/llfilesystem/lldir.cpp +++ b/indra/llfilesystem/lldir.cpp @@ -638,7 +638,7 @@ std::string LLDir::getBaseFileName(const std::string& filepath, bool strip_exten std::string LLDir::getDirName(const std::string& filepath) const { std::size_t offset = filepath.find_last_of(getDirDelimiter()); - S32 len = (offset == std::string::npos) ? 0 : offset; + auto len = (offset == std::string::npos) ? 0 : offset; std::string dirname = filepath.substr(0, len); return dirname; } @@ -883,8 +883,8 @@ std::string LLDir::getScrubbedFileName(const std::string uncleanFileName) // replace any illegal file chars with and underscore '_' for( unsigned int i = 0; i < illegalChars.length(); i++ ) { - int j = -1; - while((j = name.find(illegalChars[i])) > -1) + std::string::size_type j = -1; + while((j = name.find(illegalChars[i])) > std::string::npos) { name[j] = '_'; } -- cgit v1.2.3 From 810219d3bf27d81751d0f41b65013ca31db34ff7 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 18 Jun 2024 16:23:30 +0300 Subject: jira-archive-internal#67837 Fix LLDir::getScrubbedFileName --- indra/llfilesystem/lldir.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llfilesystem/lldir.cpp') diff --git a/indra/llfilesystem/lldir.cpp b/indra/llfilesystem/lldir.cpp index 483ef0fd02..85ae6d4d1d 100644 --- a/indra/llfilesystem/lldir.cpp +++ b/indra/llfilesystem/lldir.cpp @@ -881,10 +881,10 @@ std::string LLDir::getScrubbedFileName(const std::string uncleanFileName) std::string name(uncleanFileName); const std::string illegalChars(getForbiddenFileChars()); // replace any illegal file chars with and underscore '_' - for( unsigned int i = 0; i < illegalChars.length(); i++ ) + for( const char &ch : illegalChars) { std::string::size_type j = -1; - while((j = name.find(illegalChars[i])) > std::string::npos) + while((j = name.find(ch)) != std::string::npos) { name[j] = '_'; } -- cgit v1.2.3 From 7342ebf43aa7500afe7410b49689a3aefa669e58 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Tue, 18 Jun 2024 20:32:24 +0200 Subject: Follow-up improvements of 810219d3bf27d81751d0f41b65013ca31db34ff7 --- indra/llfilesystem/lldir.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/llfilesystem/lldir.cpp') diff --git a/indra/llfilesystem/lldir.cpp b/indra/llfilesystem/lldir.cpp index 85ae6d4d1d..8ee2c309a5 100644 --- a/indra/llfilesystem/lldir.cpp +++ b/indra/llfilesystem/lldir.cpp @@ -876,15 +876,15 @@ std::string LLDir::getTempFilename() const } // static -std::string LLDir::getScrubbedFileName(const std::string uncleanFileName) +std::string LLDir::getScrubbedFileName(std::string_view uncleanFileName) { std::string name(uncleanFileName); const std::string illegalChars(getForbiddenFileChars()); // replace any illegal file chars with and underscore '_' - for( const char &ch : illegalChars) + for (const char& ch : illegalChars) { - std::string::size_type j = -1; - while((j = name.find(ch)) != std::string::npos) + std::string::size_type j{ 0 }; + while ((j = name.find(ch, j)) != std::string::npos) { name[j] = '_'; } -- cgit v1.2.3