Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/DefaultFileSystem.cpp

Issue 29481704: Noissue - Use buffer for FileSystem IO (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Nit addressed Created July 7, 2017, 12:50 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/AdblockPlus/FileSystem.h ('k') | src/FileSystemJsObject.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/DefaultFileSystem.cpp
===================================================================
--- a/src/DefaultFileSystem.cpp
+++ b/src/DefaultFileSystem.cpp
@@ -61,30 +61,39 @@
// file paths as they are.
std::string NormalizePath(const std::string& path)
{
return path;
}
#endif
}
-std::shared_ptr<std::istream>
+FileSystem::IOBuffer
DefaultFileSystem::Read(const std::string& path) const
{
- std::shared_ptr<std::istream> result(new std::ifstream(NormalizePath(path).c_str()));
- if (result->fail())
+ std::ifstream file(NormalizePath(path).c_str(), std::ios_base::binary);
+ if (file.fail())
throw RuntimeErrorWithErrno("Failed to open " + path);
- return result;
+
+ file.seekg(0, std::ios_base::end);
+ auto dataSize = file.tellg();
+ file.seekg(0, std::ios_base::beg);
+
+ IOBuffer data(dataSize);
+ file.read(reinterpret_cast<std::ifstream::char_type*>(data.data()),
+ data.size());
+ return data;
}
void DefaultFileSystem::Write(const std::string& path,
- std::istream& data)
+ const IOBuffer& data)
{
std::ofstream file(NormalizePath(path).c_str(), std::ios_base::out | std::ios_base::binary);
- file << Utils::Slurp(data);
+ file.write(reinterpret_cast<const std::ofstream::char_type*>(data.data()),
+ data.size());
}
void DefaultFileSystem::Move(const std::string& fromPath,
const std::string& toPath)
{
if (rename(NormalizePath(fromPath).c_str(), NormalizePath(toPath).c_str()))
throw RuntimeErrorWithErrno("Failed to move " + fromPath + " to " + toPath);
}
« no previous file with comments | « include/AdblockPlus/FileSystem.h ('k') | src/FileSystemJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld