Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Unified Diff: courgette/courgette_tool.cc

Issue 2143973004: Use memory mapped file in courgette_tool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make BufferedFileReader const correct Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: courgette/courgette_tool.cc
diff --git a/courgette/courgette_tool.cc b/courgette/courgette_tool.cc
index d0fdb4e62bd5436f81a48bc6caa21b24359df31b..7ffe1e2ebb87da65a23daef101c35efdcf8a7e46 100644
--- a/courgette/courgette_tool.cc
+++ b/courgette/courgette_tool.cc
@@ -57,20 +57,17 @@ void Problem(const char* format, ...) {
class BufferedFileReader {
public:
BufferedFileReader(const base::FilePath& file_name, const char* kind) {
- int64_t file_size = 0;
- if (!base::GetFileSize(file_name, &file_size))
- Problem("Can't read %s file.", kind);
- buffer_.reserve(static_cast<size_t>(file_size));
- if (!base::ReadFileToString(file_name, &buffer_))
+ if (!buffer_.Initialize(file_name)) {
Problem("Can't read %s file.", kind);
+ }
huangs 2016/07/14 21:25:55 Can skip {}.
etiennep 2016/07/14 21:32:17 Done.
}
- const uint8_t* data() {
- return reinterpret_cast<const uint8_t*>(buffer_.data());
+ const uint8_t* data() const {
huangs 2016/07/14 21:25:55 Move into 1 line like length()? Or make length() m
etiennep 2016/07/14 21:32:17 Done.
+ return buffer_.data();
}
- size_t length() { return buffer_.length(); }
+ size_t length() const { return buffer_.length(); }
private:
- std::string buffer_;
+ base::MemoryMappedFile buffer_;
};
void WriteSinkToFile(const courgette::SinkStream *sink,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698