1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 22:33:57 +02:00

libexpr: Use single tSmallList Value discriminator for small lists

This commit is contained in:
Sergei Zimmerman 2025-06-28 15:30:40 +03:00
parent ea32580c9b
commit 1a033ee4ee
No known key found for this signature in database
GPG key ID: A9B0B557CA632325

View file

@ -25,8 +25,7 @@ typedef enum {
tPath, tPath,
tNull, tNull,
tAttrs, tAttrs,
tList1, tListSmall,
tList2,
tListN, tListN,
tThunk, tThunk,
tApp, tApp,
@ -318,8 +317,7 @@ public:
return nNull; return nNull;
case tAttrs: case tAttrs:
return nAttrs; return nAttrs;
case tList1: case tListSmall:
case tList2:
case tListN: case tListN:
return nList; return nList;
case tLambda: case tLambda:
@ -405,9 +403,9 @@ public:
void mkList(const ListBuilder & builder) void mkList(const ListBuilder & builder)
{ {
if (builder.size == 1) if (builder.size == 1)
finishValue(tList1, {.smallList = {builder.inlineElems[0]}}); finishValue(tListSmall, {.smallList = {builder.inlineElems[0], nullptr}});
else if (builder.size == 2) else if (builder.size == 2)
finishValue(tList2, {.smallList = {builder.inlineElems[0], builder.inlineElems[1]}}); finishValue(tListSmall, {.smallList = {builder.inlineElems[0], builder.inlineElems[1]}});
else else
finishValue(tListN, {.bigList = {.size = builder.size, .elems = builder.elems}}); finishValue(tListN, {.bigList = {.size = builder.size, .elems = builder.elems}});
} }
@ -453,7 +451,7 @@ public:
bool isList() const bool isList() const
{ {
return internalType == tList1 || internalType == tList2 || internalType == tListN; return internalType == tListSmall || internalType == tListN;
} }
std::span<Value * const> listItems() const std::span<Value * const> listItems() const
@ -464,12 +462,12 @@ public:
Value * const * listElems() const Value * const * listElems() const
{ {
return internalType == tList1 || internalType == tList2 ? payload.smallList : payload.bigList.elems; return internalType == tListSmall ? payload.smallList : payload.bigList.elems;
} }
size_t listSize() const size_t listSize() const
{ {
return internalType == tList1 ? 1 : internalType == tList2 ? 2 : payload.bigList.size; return internalType == tListSmall ? (payload.smallList[1] == nullptr ? 1 : 2) : payload.bigList.size;
} }
PosIdx determinePos(const PosIdx pos) const; PosIdx determinePos(const PosIdx pos) const;