mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
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>
This commit is contained in:
parent
0a74b4905c
commit
d6f1e2de21
3 changed files with 14 additions and 4 deletions
|
|
@ -1048,15 +1048,13 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, RepairF
|
||||||
/* In case we are not interested in reading the NAR: discard it. */
|
/* In case we are not interested in reading the NAR: discard it. */
|
||||||
bool narRead = false;
|
bool narRead = false;
|
||||||
Finally cleanup = [&]() {
|
Finally cleanup = [&]() {
|
||||||
if (!narRead) {
|
if (!narRead)
|
||||||
NullFileSystemObjectSink sink;
|
|
||||||
try {
|
try {
|
||||||
parseDump(sink, source);
|
source.skip(info.narSize);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// TODO: should Interrupted be handled here?
|
// TODO: should Interrupted be handled here?
|
||||||
ignoreExceptionInDestructor();
|
ignoreExceptionInDestructor();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
addTempRoot(info.path);
|
addTempRoot(info.path);
|
||||||
|
|
|
||||||
|
|
@ -255,6 +255,8 @@ struct StringSource : Source
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t read(char * data, size_t len) override;
|
size_t read(char * data, size_t len) override;
|
||||||
|
|
||||||
|
void skip(size_t len) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -242,6 +242,16 @@ size_t StringSource::read(char * data, size_t len)
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StringSource::skip(size_t len)
|
||||||
|
{
|
||||||
|
const size_t remain = s.size() - pos;
|
||||||
|
if (len > remain) {
|
||||||
|
pos = s.size();
|
||||||
|
throw EndOfFile("end of string reached");
|
||||||
|
}
|
||||||
|
pos += len;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
|
std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
|
||||||
{
|
{
|
||||||
struct SourceToSink : FinishSink
|
struct SourceToSink : FinishSink
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue