From 5cf6b2cb75f6d0facecaa457fd31cb525436e157 Mon Sep 17 00:00:00 2001 From: Philipp Otterbein Date: Mon, 30 Sep 2024 22:15:04 +0200 Subject: [PATCH] eval: remove superfluous strdup --- src/libexpr/eval-gc.hh | 1 - src/libexpr/eval.cc | 16 ++++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/libexpr/eval-gc.hh b/src/libexpr/eval-gc.hh index 3b420e418..8f0b32c1c 100644 --- a/src/libexpr/eval-gc.hh +++ b/src/libexpr/eval-gc.hh @@ -23,7 +23,6 @@ template using gc_allocator = std::allocator; # define GC_MALLOC_ATOMIC std::malloc -# define GC_STRDUP strdup struct gc {}; diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 379839ce3..9eae6078b 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -53,15 +53,6 @@ static char * allocString(size_t size) } -static char * dupString(const char * s) -{ - char * t; - t = GC_STRDUP(s); - if (!t) throw std::bad_alloc(); - return t; -} - - // When there's no need to write to the string, we can optimize away empty // string allocations. // This function handles makeImmutableString(std::string_view()) by returning @@ -832,9 +823,10 @@ static const char * * encodeContext(const NixStringContext & context) size_t n = 0; auto ctx = (const char * *) allocBytes((context.size() + 1) * sizeof(char *)); - for (auto & i : context) - ctx[n++] = dupString(i.to_string().c_str()); - ctx[n] = 0; + for (auto & i : context) { + ctx[n++] = makeImmutableString({i.to_string()}); + } + ctx[n] = nullptr; return ctx; } else return nullptr;