mirror of
https://github.com/NixOS/nix.git
synced 2025-11-23 10:49:36 +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)
|
static void prim_typeOf(EvalState & state, const PosIdx pos, Value ** args, Value & v)
|
||||||
{
|
{
|
||||||
state.forceValue(*args[0], pos);
|
state.forceValue(*args[0], pos);
|
||||||
std::string t;
|
|
||||||
switch (args[0]->type()) {
|
switch (args[0]->type()) {
|
||||||
case nInt:
|
case nInt:
|
||||||
t = "int";
|
v.mkStringNoCopy("int");
|
||||||
break;
|
break;
|
||||||
case nBool:
|
case nBool:
|
||||||
t = "bool";
|
v.mkStringNoCopy("bool");
|
||||||
break;
|
break;
|
||||||
case nString:
|
case nString:
|
||||||
t = "string";
|
v.mkStringNoCopy("string");
|
||||||
break;
|
break;
|
||||||
case nPath:
|
case nPath:
|
||||||
t = "path";
|
v.mkStringNoCopy("path");
|
||||||
break;
|
break;
|
||||||
case nNull:
|
case nNull:
|
||||||
t = "null";
|
v.mkStringNoCopy("null");
|
||||||
break;
|
break;
|
||||||
case nAttrs:
|
case nAttrs:
|
||||||
t = "set";
|
v.mkStringNoCopy("set");
|
||||||
break;
|
break;
|
||||||
case nList:
|
case nList:
|
||||||
t = "list";
|
v.mkStringNoCopy("list");
|
||||||
break;
|
break;
|
||||||
case nFunction:
|
case nFunction:
|
||||||
t = "lambda";
|
v.mkStringNoCopy("lambda");
|
||||||
break;
|
break;
|
||||||
case nExternal:
|
case nExternal:
|
||||||
t = args[0]->external()->typeOf();
|
v.mkString(args[0]->external()->typeOf());
|
||||||
break;
|
break;
|
||||||
case nFloat:
|
case nFloat:
|
||||||
t = "float";
|
v.mkStringNoCopy("float");
|
||||||
break;
|
break;
|
||||||
case nThunk:
|
case nThunk:
|
||||||
unreachable();
|
unreachable();
|
||||||
}
|
}
|
||||||
v.mkString(t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_typeOf({
|
static RegisterPrimOp primop_typeOf({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue