mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
optimization: read content of the file directly to std::string to avoid creating temporary memory.
As json format is one big string we can directly read the content of file with one call to getline() without going through generic interface to first read into stringstream and then create again a temorary string from the stringstream buffer.
This commit is contained in:
parent
2034f0ee0c
commit
c6790a8043
@ -119,10 +119,15 @@ bool LottieLoader::load(const std::string &path, bool cachePolicy)
|
||||
vCritical << "failed to open file = " << path.c_str();
|
||||
return false;
|
||||
} else {
|
||||
std::stringstream buf;
|
||||
buf << f.rdbuf();
|
||||
std::string content;
|
||||
|
||||
LottieParser parser(const_cast<char *>(buf.str().data()),
|
||||
std::getline(f, content, '\0') ;
|
||||
f.close();
|
||||
|
||||
if (content.empty()) return false;
|
||||
|
||||
const char *str = content.c_str();
|
||||
LottieParser parser(const_cast<char *>(str),
|
||||
dirname(path).c_str());
|
||||
mModel = parser.model();
|
||||
|
||||
@ -130,8 +135,6 @@ bool LottieLoader::load(const std::string &path, bool cachePolicy)
|
||||
|
||||
if (cachePolicy)
|
||||
LottieModelCache::instance().add(path, mModel);
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user