Merge pull request #7351 from NaN-git/fix-mkString

cleanup eval.hh/eval.cc
This commit is contained in:
Théophane Hufschmitt 2023-01-02 11:41:52 +01:00 committed by GitHub
commit b3285c7722
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 10 deletions

View file

@ -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 // When there's no need to write to the string, we can optimize away empty
// string allocations. // string allocations.
// This function handles makeImmutableStringWithLen(null, 0) by returning the // This function handles makeImmutableString(std::string_view()) by returning
// empty string. // the empty string.
static const char * makeImmutableStringWithLen(const char * s, size_t size) static const char * makeImmutableString(std::string_view s)
{ {
const size_t size = s.size();
if (size == 0) if (size == 0)
return ""; return "";
auto t = allocString(size + 1); auto t = allocString(size + 1);
memcpy(t, s, size); memcpy(t, s.data(), size);
t[size] = 0; t[size] = '\0';
return t; return t;
} }
static inline const char * makeImmutableString(std::string_view s) {
return makeImmutableStringWithLen(s.data(), s.size());
}
RootValue allocRootValue(Value * v) RootValue allocRootValue(Value * v)
{ {

View file

@ -60,7 +60,6 @@ void copyContext(const Value & v, PathSet & context);
typedef std::map<Path, StorePath> SrcToStore; typedef std::map<Path, StorePath> SrcToStore;
std::ostream & printValue(const EvalState & state, std::ostream & str, const Value & v);
std::string printValue(const EvalState & state, const Value & v); std::string printValue(const EvalState & state, const Value & v);
std::ostream & operator << (std::ostream & os, const ValueType t); std::ostream & operator << (std::ostream & os, const ValueType t);