Skip to content

Commit

Permalink
Use memory mapped file in courgette_tool
Browse files Browse the repository at this point in the history
Patch generation and various utilities (disasm) now use memory mapped file
instead of copying into a string buffer. This saves the equivalent of the size of
both |old_file| and |new_file| in memory when generating the patch
(~300Mb with chrome.7z).

BUG=

Review-Url: https://codereview.chromium.org/2143973004
Cr-Commit-Position: refs/heads/master@{#405599}
  • Loading branch information
etiennep authored and Commit bot committed Jul 14, 2016
1 parent 7c597ce commit f4fe06c
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions courgette/courgette_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,14 @@ 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))
if (!buffer_.Initialize(file_name))
Problem("Can't read %s file.", kind);
buffer_.reserve(static_cast<size_t>(file_size));
if (!base::ReadFileToString(file_name, &buffer_))
Problem("Can't read %s file.", kind);
}
const uint8_t* data() {
return reinterpret_cast<const uint8_t*>(buffer_.data());
}
size_t length() { return buffer_.length(); }
const uint8_t* data() const { return buffer_.data(); }
size_t length() const { return buffer_.length(); }

private:
std::string buffer_;
base::MemoryMappedFile buffer_;
};

void WriteSinkToFile(const courgette::SinkStream *sink,
Expand Down

0 comments on commit f4fe06c

Please sign in to comment.