From fa125b9b28bea25a4eeb4d39a71a481563127cb9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 1 Mar 2017 16:16:04 +0100 Subject: 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. --- src/libstore/export-import.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/libstore/export-import.cc') diff --git a/src/libstore/export-import.cc b/src/libstore/export-import.cc index 531f010d93a7..2b8ab063e18e 100644 --- a/src/libstore/export-import.cc +++ b/src/libstore/export-import.cc @@ -70,9 +70,8 @@ Paths Store::importPaths(Source & source, std::shared_ptr accessor, if (n != 1) throw Error("input doesn't look like something created by ‘nix-store --export’"); /* Extract the NAR from the source. */ - TeeSource tee(source); - ParseSink sink; - parseDump(sink, tee); + TeeSink tee(source); + parseDump(tee, tee.source); uint32_t magic = readInt(source); if (magic != exportMagic) @@ -89,14 +88,14 @@ Paths Store::importPaths(Source & source, std::shared_ptr accessor, info.deriver = readString(source); if (info.deriver != "") assertStorePath(info.deriver); - info.narHash = hashString(htSHA256, *tee.data); - info.narSize = tee.data->size(); + info.narHash = hashString(htSHA256, *tee.source.data); + info.narSize = tee.source.data->size(); // Ignore optional legacy signature. if (readInt(source) == 1) readString(source); - addToStore(info, tee.data, false, dontCheckSigs, accessor); + addToStore(info, tee.source.data, false, dontCheckSigs, accessor); res.push_back(info.path); } -- cgit 1.4.1