mirror of
https://github.com/NixOS/nix.git
synced 2025-11-18 16:29:36 +01: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
|
|
@ -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