diff options
author | Théophane Hufschmitt <7226587+thufschmitt@users.noreply.github.com> | 2023-01-02 11:41:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-02 11:41:52 +0100 |
commit | b3285c77223445067a15f4aa81103e2fc28ac582 (patch) | |
tree | c2251bcf8f7c69a54cfb187c033c63e8f66a92a4 /src/libexpr/eval.cc | |
parent | e8a3e581710d43e8df12bee0b2bd10ae69159b04 (diff) | |
parent | 8af839f48c795370df704c8dd40544c88950c1ed (diff) |
Merge pull request #7351 from NaN-git/fix-mkString
cleanup eval.hh/eval.cc
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r-- | src/libexpr/eval.cc | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 084ccbee2..ebf14b659 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -67,22 +67,19 @@ static char * dupString(const char * s) // When there's no need to write to the string, we can optimize away empty // string allocations. -// This function handles makeImmutableStringWithLen(null, 0) by returning the -// empty string. -static const char * makeImmutableStringWithLen(const char * s, size_t size) +// This function handles makeImmutableString(std::string_view()) by returning +// the empty string. +static const char * makeImmutableString(std::string_view s) { + const size_t size = s.size(); if (size == 0) return ""; auto t = allocString(size + 1); - memcpy(t, s, size); - t[size] = 0; + memcpy(t, s.data(), size); + t[size] = '\0'; return t; } -static inline const char * makeImmutableString(std::string_view s) { - return makeImmutableStringWithLen(s.data(), s.size()); -} - RootValue allocRootValue(Value * v) { |