From 505640baec97f7fcbf3c0629ef0a201a29bbe6e4 Mon Sep 17 00:00:00 2001 From: NaN Date: Sun, 14 Jul 2024 03:15:25 +0200 Subject: [PATCH] libexpr/eval.cc: remove unnecessary C string conversion Change-Id: I5b7c21df84ff8ff64cf6a1e261fc3729a06bd4f6 --- src/libexpr/eval.cc | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 2ef3abc52..ced92136b 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -65,19 +65,6 @@ static char * allocString(size_t size) } -static char * dupString(const char * s) -{ - char * t; -#if HAVE_BOEHMGC - t = GC_STRDUP(s); -#else - t = strdup(s); -#endif - 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 @@ -889,7 +876,7 @@ static void copyContextToValue(Value & v, const NixStringContext & context) v.string.context = (const char * *) allocBytes((context.size() + 1) * sizeof(char *)); for (auto & i : context) - v.string.context[n++] = dupString(i.to_string().c_str()); + v.string.context[n++] = makeImmutableString(i.to_string()); v.string.context[n] = 0; } }