mirror of
https://github.com/NixOS/nix
synced 2025-06-30 03:23:16 +02:00
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.
This commit is contained in:
parent
f61f67ddee
commit
fa125b9b28
3 changed files with 21 additions and 10 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue