1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-10-18 00:16:11 -04:00

Merge pull request #11620 from NaN-git/cleanup-eval

eval: remove superfluous strdup
This commit is contained in:
Robert Hensing 2024-10-01 14:48:29 +02:00 committed by GitHub
commit dc89eab7f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 13 deletions

View file

@ -23,7 +23,6 @@ template<typename T>
using gc_allocator = std::allocator<T>; using gc_allocator = std::allocator<T>;
# define GC_MALLOC_ATOMIC std::malloc # define GC_MALLOC_ATOMIC std::malloc
# define GC_STRDUP strdup
struct gc struct gc
{}; {};

View file

@ -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 // When there's no need to write to the string, we can optimize away empty
// string allocations. // string allocations.
// This function handles makeImmutableString(std::string_view()) by returning // This function handles makeImmutableString(std::string_view()) by returning
@ -832,9 +823,10 @@ static const char * * encodeContext(const NixStringContext & context)
size_t n = 0; size_t n = 0;
auto ctx = (const char * *) auto ctx = (const char * *)
allocBytes((context.size() + 1) * sizeof(char *)); allocBytes((context.size() + 1) * sizeof(char *));
for (auto & i : context) for (auto & i : context) {
ctx[n++] = dupString(i.to_string().c_str()); ctx[n++] = makeImmutableString({i.to_string()});
ctx[n] = 0; }
ctx[n] = nullptr;
return ctx; return ctx;
} else } else
return nullptr; return nullptr;