Skip to content

Commit d6f1e2d

Browse files
Merge pull request #14323 from NixOS/skip-nar-parse
addToStore(): Don't parse the NAR * StringSource: Implement skip() This is slightly faster than doing a read() into a buffer just to discard the data. * LocalStore::addToStore(): Skip unnecessary NARs rather than parsing them Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 0a74b49 commit d6f1e2d

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/libstore/local-store.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,15 +1048,13 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, RepairF
10481048
/* In case we are not interested in reading the NAR: discard it. */
10491049
bool narRead = false;
10501050
Finally cleanup = [&]() {
1051-
if (!narRead) {
1052-
NullFileSystemObjectSink sink;
1051+
if (!narRead)
10531052
try {
1054-
parseDump(sink, source);
1053+
source.skip(info.narSize);
10551054
} catch (...) {
10561055
// TODO: should Interrupted be handled here?
10571056
ignoreExceptionInDestructor();
10581057
}
1059-
}
10601058
};
10611059

10621060
addTempRoot(info.path);

src/libutil/include/nix/util/serialise.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ struct StringSource : Source
255255
}
256256

257257
size_t read(char * data, size_t len) override;
258+
259+
void skip(size_t len) override;
258260
};
259261

260262
/**

src/libutil/serialise.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ size_t StringSource::read(char * data, size_t len)
242242
return n;
243243
}
244244

245+
void StringSource::skip(size_t len)
246+
{
247+
const size_t remain = s.size() - pos;
248+
if (len > remain) {
249+
pos = s.size();
250+
throw EndOfFile("end of string reached");
251+
}
252+
pos += len;
253+
}
254+
245255
std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
246256
{
247257
struct SourceToSink : FinishSink

0 commit comments

Comments
 (0)