Skip to content
Snippets Groups Projects
Commit fc8237e6 authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Clean up mountains of string temporaries from LLDiskCache::metaDataToFilepath

parent 16f26f55
No related branches found
No related tags found
No related merge requests found
...@@ -179,11 +179,12 @@ const std::string LLDiskCache::assetTypeToString(LLAssetType::EType at) ...@@ -179,11 +179,12 @@ const std::string LLDiskCache::assetTypeToString(LLAssetType::EType at)
return std::string("UNKNOWN"); return std::string("UNKNOWN");
} }
const std::string LLDiskCache::metaDataToFilepath(const std::string id, const std::string LLDiskCache::metaDataToFilepath(const LLUUID& id,
LLAssetType::EType at, LLAssetType::EType at)
const std::string extra_info)
{ {
return llformat("%s%s%s_%s_%s", mCacheDir.c_str(), gDirUtilp->getDirDelimiter().c_str(), mCacheFilenamePrefix.c_str(), id.c_str(), (extra_info.empty() ? "0" : extra_info.c_str())); std::string uuidstr;
id.toString(uuidstr);
return llformat("%s%s%s_%s", mCacheDir.c_str(), gDirUtilp->getDirDelimiter().c_str(), mCacheFilenamePrefix.c_str(), uuidstr.c_str());
} }
void LLDiskCache::updateFileAccessTime(const std::string file_path) void LLDiskCache::updateFileAccessTime(const std::string file_path)
...@@ -250,9 +251,9 @@ void LLDiskCache::clearCache() ...@@ -250,9 +251,9 @@ void LLDiskCache::clearCache()
* likely just fine * likely just fine
*/ */
#if LL_WINDOWS #if LL_WINDOWS
std::wstring cache_path(ll_convert_string_to_wide(mCacheDir)); boost::filesystem::path cache_path(ll_convert_string_to_wide(mCacheDir));
#else #else
std::string cache_path(mCacheDir); boost::filesystem::path cache_path(mCacheDir);
#endif #endif
if (boost::filesystem::is_directory(cache_path)) if (boost::filesystem::is_directory(cache_path))
{ {
...@@ -283,9 +284,9 @@ uintmax_t LLDiskCache::dirFileSize(const std::string dir) ...@@ -283,9 +284,9 @@ uintmax_t LLDiskCache::dirFileSize(const std::string dir)
* is an easy win. * is an easy win.
*/ */
#if LL_WINDOWS #if LL_WINDOWS
std::wstring dir_path(ll_convert_string_to_wide(dir)); boost::filesystem::path dir_path(ll_convert_string_to_wide(dir));
#else #else
std::string dir_path(dir); boost::filesystem::path dir_path(dir);
#endif #endif
if (boost::filesystem::is_directory(dir_path)) if (boost::filesystem::is_directory(dir_path))
{ {
......
...@@ -104,9 +104,8 @@ class LLDiskCache : ...@@ -104,9 +104,8 @@ class LLDiskCache :
* so many things had to be pushed back there to accomodate it, that I * so many things had to be pushed back there to accomodate it, that I
* decided to move it here. Still not sure that's completely right. * decided to move it here. Still not sure that's completely right.
*/ */
const std::string metaDataToFilepath(const std::string id, const std::string metaDataToFilepath(const LLUUID& id,
LLAssetType::EType at, LLAssetType::EType at);
const std::string extra_info);
/** /**
* Update the "last write time" of a file to "now". This must be called whenever a * Update the "last write time" of a file to "now". This must be called whenever a
......
...@@ -48,10 +48,7 @@ LLFileSystem::LLFileSystem(const LLUUID& file_id, const LLAssetType::EType file_ ...@@ -48,10 +48,7 @@ LLFileSystem::LLFileSystem(const LLUUID& file_id, const LLAssetType::EType file_
// static // static
bool LLFileSystem::getExists(const LLUUID& file_id, const LLAssetType::EType file_type) bool LLFileSystem::getExists(const LLUUID& file_id, const LLAssetType::EType file_type)
{ {
std::string id_str; const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(file_id, file_type);
file_id.toString(id_str);
const std::string extra_info = "";
const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(id_str, file_type, extra_info);
llifstream file(filename, std::ios::binary); llifstream file(filename, std::ios::binary);
if (file.is_open()) if (file.is_open())
...@@ -65,10 +62,7 @@ bool LLFileSystem::getExists(const LLUUID& file_id, const LLAssetType::EType fil ...@@ -65,10 +62,7 @@ bool LLFileSystem::getExists(const LLUUID& file_id, const LLAssetType::EType fil
// static // static
bool LLFileSystem::removeFile(const LLUUID& file_id, const LLAssetType::EType file_type) bool LLFileSystem::removeFile(const LLUUID& file_id, const LLAssetType::EType file_type)
{ {
std::string id_str; const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(file_id, file_type);
file_id.toString(id_str);
const std::string extra_info = "";
const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(id_str, file_type, extra_info);
LLFile::remove(filename.c_str()); LLFile::remove(filename.c_str());
...@@ -79,14 +73,8 @@ bool LLFileSystem::removeFile(const LLUUID& file_id, const LLAssetType::EType fi ...@@ -79,14 +73,8 @@ bool LLFileSystem::removeFile(const LLUUID& file_id, const LLAssetType::EType fi
bool LLFileSystem::renameFile(const LLUUID& old_file_id, const LLAssetType::EType old_file_type, bool LLFileSystem::renameFile(const LLUUID& old_file_id, const LLAssetType::EType old_file_type,
const LLUUID& new_file_id, const LLAssetType::EType new_file_type) const LLUUID& new_file_id, const LLAssetType::EType new_file_type)
{ {
std::string old_id_str; const std::string old_filename = LLDiskCache::getInstance()->metaDataToFilepath(old_file_id, old_file_type);
old_file_id.toString(old_id_str); const std::string new_filename = LLDiskCache::getInstance()->metaDataToFilepath(new_file_id, new_file_type);
const std::string extra_info = "";
const std::string old_filename = LLDiskCache::getInstance()->metaDataToFilepath(old_id_str, old_file_type, extra_info);
std::string new_id_str;
new_file_id.toString(new_id_str);
const std::string new_filename = LLDiskCache::getInstance()->metaDataToFilepath(new_id_str, new_file_type, extra_info);
// Rename needs the new file to not exist. // Rename needs the new file to not exist.
LLFileSystem::removeFile(new_file_id, new_file_type); LLFileSystem::removeFile(new_file_id, new_file_type);
...@@ -97,7 +85,7 @@ bool LLFileSystem::renameFile(const LLUUID& old_file_id, const LLAssetType::ETyp ...@@ -97,7 +85,7 @@ bool LLFileSystem::renameFile(const LLUUID& old_file_id, const LLAssetType::ETyp
// failed but the original code does not and doing so seems to // failed but the original code does not and doing so seems to
// break a lot of things so we go with the flow... // break a lot of things so we go with the flow...
//return FALSE; //return FALSE;
LL_WARNS() << "Failed to rename " << old_file_id << " to " << new_id_str << " reason: " << strerror(errno) << LL_ENDL; LL_WARNS() << "Failed to rename " << old_file_id << " to " << new_file_id << " reason: " << strerror(errno) << LL_ENDL;
} }
return TRUE; return TRUE;
...@@ -106,10 +94,7 @@ bool LLFileSystem::renameFile(const LLUUID& old_file_id, const LLAssetType::ETyp ...@@ -106,10 +94,7 @@ bool LLFileSystem::renameFile(const LLUUID& old_file_id, const LLAssetType::ETyp
// static // static
S32 LLFileSystem::getFileSize(const LLUUID& file_id, const LLAssetType::EType file_type) S32 LLFileSystem::getFileSize(const LLUUID& file_id, const LLAssetType::EType file_type)
{ {
std::string id_str; const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(file_id, file_type);
file_id.toString(id_str);
const std::string extra_info = "";
const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(id_str, file_type, extra_info);
S32 file_size = 0; S32 file_size = 0;
llifstream file(filename, std::ios::binary); llifstream file(filename, std::ios::binary);
...@@ -126,10 +111,7 @@ BOOL LLFileSystem::read(U8* buffer, S32 bytes) ...@@ -126,10 +111,7 @@ BOOL LLFileSystem::read(U8* buffer, S32 bytes)
{ {
BOOL success = TRUE; BOOL success = TRUE;
std::string id; const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(mFileID, mFileType);
mFileID.toString(id);
const std::string extra_info = "";
const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(id, mFileType, extra_info);
llifstream file(filename, std::ios::binary); llifstream file(filename, std::ios::binary);
if (file.is_open()) if (file.is_open())
...@@ -177,10 +159,7 @@ BOOL LLFileSystem::eof() ...@@ -177,10 +159,7 @@ BOOL LLFileSystem::eof()
BOOL LLFileSystem::write(const U8* buffer, S32 bytes) BOOL LLFileSystem::write(const U8* buffer, S32 bytes)
{ {
std::string id_str; const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(mFileID, mFileType);
mFileID.toString(id_str);
const std::string extra_info = "";
const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(id_str, mFileType, extra_info);
BOOL success = FALSE; BOOL success = FALSE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment