mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
libexpr: Use mkStringNoCopy in prim_typeOf
This would lead to an unnecessary allocation. Not a significant issue by any means, but it doesn't have to allocate for most cases.
This commit is contained in:
parent
d62cfc1c97
commit
34181afc6a
1 changed files with 10 additions and 12 deletions
|
|
@ -483,42 +483,40 @@ void prim_exec(EvalState & state, const PosIdx pos, Value ** args, Value & v)
|
|||
static void prim_typeOf(EvalState & state, const PosIdx pos, Value ** args, Value & v)
|
||||
{
|
||||
state.forceValue(*args[0], pos);
|
||||
std::string t;
|
||||
switch (args[0]->type()) {
|
||||
case nInt:
|
||||
t = "int";
|
||||
v.mkStringNoCopy("int");
|
||||
break;
|
||||
case nBool:
|
||||
t = "bool";
|
||||
v.mkStringNoCopy("bool");
|
||||
break;
|
||||
case nString:
|
||||
t = "string";
|
||||
v.mkStringNoCopy("string");
|
||||
break;
|
||||
case nPath:
|
||||
t = "path";
|
||||
v.mkStringNoCopy("path");
|
||||
break;
|
||||
case nNull:
|
||||
t = "null";
|
||||
v.mkStringNoCopy("null");
|
||||
break;
|
||||
case nAttrs:
|
||||
t = "set";
|
||||
v.mkStringNoCopy("set");
|
||||
break;
|
||||
case nList:
|
||||
t = "list";
|
||||
v.mkStringNoCopy("list");
|
||||
break;
|
||||
case nFunction:
|
||||
t = "lambda";
|
||||
v.mkStringNoCopy("lambda");
|
||||
break;
|
||||
case nExternal:
|
||||
t = args[0]->external()->typeOf();
|
||||
v.mkString(args[0]->external()->typeOf());
|
||||
break;
|
||||
case nFloat:
|
||||
t = "float";
|
||||
v.mkStringNoCopy("float");
|
||||
break;
|
||||
case nThunk:
|
||||
unreachable();
|
||||
}
|
||||
v.mkString(t);
|
||||
}
|
||||
|
||||
static RegisterPrimOp primop_typeOf({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue