libexpr: move null to auxiliary storage

we only need the one object for it. there's no need to waste precious
bits of the value internal type enum for this simple singleton datum.

Change-Id: Ie314b5bf429015e518798d9d65ad8ab2bb84a38e
This commit is contained in:
eldritch horrors
2025-09-28 00:02:20 +02:00
parent 5def7559a6
commit b1ffae3ccd
3 changed files with 13 additions and 8 deletions
+1
View File
@@ -108,6 +108,7 @@ std::string showType(const Value & v)
case Value::Acb::tExternal:
return v.external()->showType();
case Value::Acb::tFloat:
case Value::Acb::tNull:
return std::string(showType(v.type()));
}
#pragma GCC diagnostic pop
+2
View File
@@ -12,6 +12,8 @@ namespace nix
static const Value::List emptyListData{.size = 0};
Value Value::EMPTY_LIST{Value::list_t{}, &emptyListData};
const Value::Null Value::NULL_ACB = {{Value::Acb::tNull}};
static void copyContextToValue(Value::String & s, const NixStringContext & context)
{
if (!context.empty()) {
+10 -8
View File
@@ -26,7 +26,6 @@ typedef enum {
tInt = 1,
tBool,
tString,
tNull,
tAttrs,
tList,
tThunk,
@@ -214,6 +213,9 @@ public:
struct String;
struct Acb;
struct Null;
static const Null NULL_ACB;
// Discount `using NewValueAs::*;`
// NOLINTNEXTLINE(bugprone-macro-parentheses)
@@ -416,10 +418,7 @@ public:
}
/// Constructs a nix language value of the singleton type "null".
Value(null_t)
: internalType(tNull)
, _empty{0, 0}
{ }
Value(null_t) : Value(NULL_ACB) {}
/// Constructs a nix language value of type "set", with the attribute
/// bindings pointed to by @ref bindings.
@@ -640,6 +639,7 @@ public:
enum {
tExternal,
tFloat,
tNull,
} type;
};
struct External : Acb
@@ -650,6 +650,8 @@ public:
{
NixFloat value;
};
struct Null : Acb
{};
union
{
@@ -710,7 +712,6 @@ public:
case tBool: return nBool;
case tString:
return _string->isPath() ? nPath : nString;
case tNull: return nNull;
case tAttrs: return nAttrs;
case tList:
return nList;
@@ -723,6 +724,8 @@ public:
return nExternal;
case Acb::tFloat:
return nFloat;
case Acb::tNull:
return nNull;
}
case tThunk:
return nThunk;
@@ -790,8 +793,7 @@ public:
inline void mkNull()
{
clearValue();
internalType = tNull;
*this = {NewValueAs::null};
}
inline void mkAttrs(Bindings * a)