aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-04 07:32:31 +0100
committereldritch horrors <pennae@lix.systems>2024-03-04 07:32:31 +0100
commitdd180911d8ecf737e6b2ceb89d6797965fcc3b78 (patch)
tree633078cc7b7f743421e04dc51ec8a4bbda76ada6 /src/libstore
parent076844e3868f108ce0d1523e2db069f7e71c9990 (diff)
Merge pull request #9582 from pennae/misc-opts
a packet of small optimizations (cherry picked from commit ee439734e924eb337a869ff2e48aff8b989198bc) Change-Id: I125d870710750a32a0dece48f39a3e9132b0d023
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/derived-path.cc8
-rw-r--r--src/libstore/local-store.cc22
2 files changed, 19 insertions, 11 deletions
diff --git a/src/libstore/derived-path.cc b/src/libstore/derived-path.cc
index 47d784deb..214caab54 100644
--- a/src/libstore/derived-path.cc
+++ b/src/libstore/derived-path.cc
@@ -11,9 +11,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) \
@@ -21,13 +21,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
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 17b4ecc73..554e13e3d 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -15,6 +15,8 @@
#include <algorithm>
#include <cstring>
+#include <memory>
+#include <new>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
@@ -1286,7 +1288,11 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name
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
@@ -1295,13 +1301,18 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name
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;
@@ -1327,7 +1338,8 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name
else
writeFile(tempPath, bothSource);
- dump.clear();
+ dumpBuffer.reset();
+ dump = {};
}
auto [hash, size] = hashSink->finish();