lib.gvariant: remove throwIfNot usage

throwIfNot sends our error message through a function call, even if the
error condition doesn't trigger. This requires a lot of thunk allocation
that can be easily avoided.
This commit is contained in:
Eman Resu 2026-05-26 13:37:16 -04:00
commit feb74fca37

View file

@ -194,9 +194,11 @@ rec {
vs = map mkValue (
if elems == [ ] then throw "Please create empty array with mkEmptyArray." else elems
);
elemType = lib.throwIfNot (lib.all (t: (head vs).type == t) (
map (v: v.type) vs
)) "Elements in a list should have same type." (head vs).type;
elemType =
if lib.any (t: (head vs).type != t) (map (v: v.type) vs) then
throw "Elements in a list should have same type."
else
(head vs).type;
in
mkPrimitive (type.arrayOf elemType) vs
// {