mirror of
https://github.com/NixOS/nix
synced 2025-06-28 09:31:16 +02:00
Merge pull request #9582 from pennae/misc-opts
a packet of small optimizations
This commit is contained in:
commit
ee439734e9
20 changed files with 148 additions and 76 deletions
|
@ -12,9 +12,9 @@ namespace nix {
|
|||
bool MY_TYPE ::operator COMPARATOR (const MY_TYPE & other) const \
|
||||
{ \
|
||||
const MY_TYPE* me = this; \
|
||||
auto fields1 = std::make_tuple<const CHILD_TYPE &, const FIELD_TYPE &>(*me->drvPath, me->FIELD); \
|
||||
auto fields1 = std::tie(*me->drvPath, me->FIELD); \
|
||||
me = &other; \
|
||||
auto fields2 = std::make_tuple<const CHILD_TYPE &, const FIELD_TYPE &>(*me->drvPath, me->FIELD); \
|
||||
auto fields2 = std::tie(*me->drvPath, me->FIELD); \
|
||||
return fields1 COMPARATOR fields2; \
|
||||
}
|
||||
#define CMP(CHILD_TYPE, MY_TYPE, FIELD) \
|
||||
|
@ -22,13 +22,9 @@ namespace nix {
|
|||
CMP_ONE(CHILD_TYPE, MY_TYPE, FIELD, !=) \
|
||||
CMP_ONE(CHILD_TYPE, MY_TYPE, FIELD, <)
|
||||
|
||||
#define FIELD_TYPE std::string
|
||||
CMP(SingleDerivedPath, SingleDerivedPathBuilt, output)
|
||||
#undef FIELD_TYPE
|
||||
|
||||
#define FIELD_TYPE OutputsSpec
|
||||
CMP(SingleDerivedPath, DerivedPathBuilt, outputs)
|
||||
#undef FIELD_TYPE
|
||||
|
||||
#undef CMP
|
||||
#undef CMP_ONE
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/select.h>
|
||||
|
@ -1147,7 +1149,11 @@ StorePath LocalStore::addToStoreFromDump(
|
|||
path. */
|
||||
bool inMemory = false;
|
||||
|
||||
std::string dump;
|
||||
struct Free {
|
||||
void operator()(void* v) { free(v); }
|
||||
};
|
||||
std::unique_ptr<char, Free> dumpBuffer(nullptr);
|
||||
std::string_view dump;
|
||||
|
||||
/* Fill out buffer, and decide whether we are working strictly in
|
||||
memory based on whether we break out because the buffer is full
|
||||
|
@ -1156,13 +1162,18 @@ StorePath LocalStore::addToStoreFromDump(
|
|||
auto oldSize = dump.size();
|
||||
constexpr size_t chunkSize = 65536;
|
||||
auto want = std::min(chunkSize, settings.narBufferSize - oldSize);
|
||||
dump.resize(oldSize + want);
|
||||
if (auto tmp = realloc(dumpBuffer.get(), oldSize + want)) {
|
||||
dumpBuffer.release();
|
||||
dumpBuffer.reset((char*) tmp);
|
||||
} else {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
auto got = 0;
|
||||
Finally cleanup([&]() {
|
||||
dump.resize(oldSize + got);
|
||||
dump = {dumpBuffer.get(), dump.size() + got};
|
||||
});
|
||||
try {
|
||||
got = source.read(dump.data() + oldSize, want);
|
||||
got = source.read(dumpBuffer.get() + oldSize, want);
|
||||
} catch (EndOfFile &) {
|
||||
inMemory = true;
|
||||
break;
|
||||
|
@ -1185,7 +1196,8 @@ StorePath LocalStore::addToStoreFromDump(
|
|||
|
||||
restorePath(tempPath, bothSource, method.getFileIngestionMethod());
|
||||
|
||||
dump.clear();
|
||||
dumpBuffer.reset();
|
||||
dump = {};
|
||||
}
|
||||
|
||||
auto [hash, size] = hashSink->finish();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue