diff options
author | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-01 00:19:02 +0000 |
---|---|---|
committer | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-01 00:19:02 +0000 |
commit | fbd31eb81436cf7f6d4f9ea3683c100f112361e6 (patch) | |
tree | b0c191290d86ac3a70209fb0984320a88c1e3c07 /courgette/ensemble_apply.cc | |
parent | 4b764ded93509c0a58a1a8cca10b0964fdcca41d (diff) | |
download | chromium_src-fbd31eb81436cf7f6d4f9ea3683c100f112361e6.zip chromium_src-fbd31eb81436cf7f6d4f9ea3683c100f112361e6.tar.gz chromium_src-fbd31eb81436cf7f6d4f9ea3683c100f112361e6.tar.bz2 |
Implementation of an STL compatible allocator for Courgette on Windows.
This is to better handle low memory situations when applying a differential
patch to a large Chrome setup.
For reading input files, I'm also switching to using memory mapped files
instead of ReadFileToString to reduce the load on the heap.
TEST=courgette.exe should succeed in applying a patch between two
chrome 10.x archives on an XP machine with 180MB of physical memory and
no page file.
BUG=72459,73209
Review URL: http://codereview.chromium.org/6597038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76320 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette/ensemble_apply.cc')
-rw-r--r-- | courgette/ensemble_apply.cc | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/courgette/ensemble_apply.cc b/courgette/ensemble_apply.cc index 0785598..c865bfa 100644 --- a/courgette/ensemble_apply.cc +++ b/courgette/ensemble_apply.cc @@ -364,50 +364,32 @@ Status ApplyEnsemblePatch(SourceStream* base, Status ApplyEnsemblePatch(const FilePath::CharType* old_file_name, const FilePath::CharType* patch_file_name, const FilePath::CharType* new_file_name) { - Status status; - // First read enough of the patch file to validate the header is well-formed. // A few varint32 numbers should fit in 100. FilePath patch_file_path(patch_file_name); - const int BIG_ENOUGH_FOR_HEADER = 100; - char buffer[BIG_ENOUGH_FOR_HEADER]; - int read_count = - file_util::ReadFile(patch_file_path, buffer, sizeof(buffer)); - if (read_count < 0) + file_util::MemoryMappedFile patch_file; + if (!patch_file.Initialize(patch_file_path)) return C_READ_OPEN_ERROR; // 'Dry-run' the first step of the patch process to validate format of header. SourceStream patch_header_stream; - patch_header_stream.Init(buffer, read_count); + patch_header_stream.Init(patch_file.data(), patch_file.length()); EnsemblePatchApplication patch_process; - status = patch_process.ReadHeader(&patch_header_stream); + Status status = patch_process.ReadHeader(&patch_header_stream); if (status != C_OK) return status; - // Header smells good so read the whole patch file for real. - int64 patch_file_size = 0; - if (!file_util::GetFileSize(patch_file_path, &patch_file_size)) - return C_READ_ERROR; - std::string patch_file_buffer; - patch_file_buffer.reserve(static_cast<size_t>(patch_file_size)); - if (!file_util::ReadFileToString(patch_file_path, &patch_file_buffer)) - return C_READ_ERROR; - // Read the old_file. FilePath old_file_path(old_file_name); - int64 old_file_size = 0; - if (!file_util::GetFileSize(old_file_path, &old_file_size)) - return C_READ_ERROR; - std::string old_file_buffer; - old_file_buffer.reserve(static_cast<size_t>(old_file_size)); - if (!file_util::ReadFileToString(old_file_path, &old_file_buffer)) + file_util::MemoryMappedFile old_file; + if (!old_file.Initialize(old_file_path)) return C_READ_ERROR; // Apply patch on streams. SourceStream old_source_stream; SourceStream patch_source_stream; - old_source_stream.Init(old_file_buffer); - patch_source_stream.Init(patch_file_buffer); + old_source_stream.Init(old_file.data(), old_file.length()); + patch_source_stream.Init(patch_file.data(), patch_file.length()); SinkStream new_sink_stream; status = ApplyEnsemblePatch(&old_source_stream, &patch_source_stream, &new_sink_stream); |