diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-03-01 16:16:04 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-03-01 16:16:04 +0100 |
commit | fa125b9b28bea25a4eeb4d39a71a481563127cb9 (patch) | |
tree | c1c563a532a888a21afe402a6beb88423cede367 /src/libutil | |
parent | f61f67ddee12a976a0a6a20652e7c545b49fa46c (diff) |
TeeSink: Pre-reserve string space
When receiving a very large file, this can prevent the string from
having tobe copied, which temporarily doubles memory consumption.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/archive.hh | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libutil/archive.hh b/src/libutil/archive.hh index d58b91df0..c067cd2ad 100644 --- a/src/libutil/archive.hh +++ b/src/libutil/archive.hh @@ -70,6 +70,19 @@ struct ParseSink virtual void createSymlink(const Path & path, const string & target) { }; }; +struct TeeSink : ParseSink +{ + TeeSource source; + + TeeSink(Source & source) : source(source) { } + + void preallocateContents(unsigned long long size) override + { + source.data->reserve(source.data->size() + size + 1024); + }; + +}; + void parseDump(ParseSink & sink, Source & source); void restorePath(const Path & path, Source & source); |