mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-02 01:33:04 +00:00
Optimizations
Using a faster method to read files.
This commit is contained in:
1 file changed
+12
-3
+12
-3
@@ -689,7 +689,8 @@ std::string getMD5(const std::string &data)
|
|||||||
std::string fileGet(const std::string &path, bool binary, bool scope_limit)
|
std::string fileGet(const std::string &path, bool binary, bool scope_limit)
|
||||||
{
|
{
|
||||||
std::ifstream infile;
|
std::ifstream infile;
|
||||||
std::stringstream strstrm;
|
//std::stringstream strstrm;
|
||||||
|
std::string content;
|
||||||
std::ios::openmode mode = binary ? std::ios::binary : std::ios::in;
|
std::ios::openmode mode = binary ? std::ios::binary : std::ios::in;
|
||||||
|
|
||||||
if(scope_limit)
|
if(scope_limit)
|
||||||
@@ -706,11 +707,19 @@ std::string fileGet(const std::string &path, bool binary, bool scope_limit)
|
|||||||
infile.open(path, mode);
|
infile.open(path, mode);
|
||||||
if(infile)
|
if(infile)
|
||||||
{
|
{
|
||||||
|
//move to a faster method
|
||||||
|
infile.seekg(0, std::ios::end);
|
||||||
|
content.resize(infile.tellg());
|
||||||
|
infile.seekg(0, std::ios::beg);
|
||||||
|
infile.read(&content[0], content.size());
|
||||||
|
infile.close();
|
||||||
|
/*
|
||||||
strstrm << infile.rdbuf();
|
strstrm << infile.rdbuf();
|
||||||
infile.close();
|
infile.close();
|
||||||
return strstrm.str();
|
return strstrm.str();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
return std::string();
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fileExist(const std::string &path)
|
bool fileExist(const std::string &path)
|
||||||
@@ -759,7 +768,7 @@ int fileWrite(const std::string &path, const std::string &content, bool overwrit
|
|||||||
std::ios_base::openmode mode = overwrite ? std::ios_base::out : std::ios_base::app;
|
std::ios_base::openmode mode = overwrite ? std::ios_base::out : std::ios_base::app;
|
||||||
mode |= std::ios_base::binary;
|
mode |= std::ios_base::binary;
|
||||||
outfile.open(path, mode);
|
outfile.open(path, mode);
|
||||||
outfile << content << std::endl;
|
outfile << content;
|
||||||
outfile.close();
|
outfile.close();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user