diff options
author | sra@chromium.org <sra@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 21:18:48 +0000 |
---|---|---|
committer | sra@chromium.org <sra@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 21:18:48 +0000 |
commit | 6db3cd4ebccf65c9bbe1bb6d6239ec103caaf518 (patch) | |
tree | c2ab9d415c80ae62ff06fdbb8be3472271daacb0 /courgette/streams.cc | |
parent | ce910b9d066453ea491473c4ef9e73b163a58d6d (diff) | |
download | chromium_src-6db3cd4ebccf65c9bbe1bb6d6239ec103caaf518.zip chromium_src-6db3cd4ebccf65c9bbe1bb6d6239ec103caaf518.tar.gz chromium_src-6db3cd4ebccf65c9bbe1bb6d6239ec103caaf518.tar.bz2 |
Improved memory usage while applying patch.
Reduced total size of allocations from 520MB to 318MB.
The general technique is to allocate the correct size rather than grow into
the correct size and overshoot.
1. Find file sizes and allocate buffers of that size for the input files.
2. Pre-allocate a buffer for the collected inputs for the final diff.
3. Calculate the size for (2) during compression and include it in the patch
header.
The courgette.exe command line tool now calls the same ApplyEnsemblePatch
entry point that is called by the installer. This ensures measurements of
courgette.exe are a better reflection of the installer.
BUG=72459
Review URL: http://codereview.chromium.org/6546008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75787 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette/streams.cc')
-rw-r--r-- | courgette/streams.cc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/courgette/streams.cc b/courgette/streams.cc index 26c7f2e..32dbf6b 100644 --- a/courgette/streams.cc +++ b/courgette/streams.cc @@ -211,8 +211,12 @@ void SinkStream::WriteSizeVarint32(size_t value) { void SinkStream::Append(SinkStream* other) { Write(other->buffer_.c_str(), other->buffer_.size()); - other->buffer_.clear(); - other->buffer_.reserve(0); // Non-binding request to reduce storage. + other->Retire(); +} + +void SinkStream::Retire() { + buffer_.clear(); + buffer_.reserve(0); // Non-binding request to reduce storage. } //////////////////////////////////////////////////////////////////////////////// @@ -335,6 +339,14 @@ void SinkStreamSet::CopyHeaderTo(SinkStream* header) { bool SinkStreamSet::CopyTo(SinkStream *combined_stream) { SinkStream header; CopyHeaderTo(&header); + + // Reserve the correct amount of storage. + size_t length = header.Length(); + for (size_t i = 0; i < count_; ++i) { + length += stream(i)->Length(); + } + combined_stream->Reserve(length); + combined_stream->Append(&header); for (size_t i = 0; i < count_; ++i) { combined_stream->Append(stream(i)); |