minimize extra dv::value copies
This commit is contained in:
@@ -136,7 +136,13 @@ public:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Argument {name, type, optional, def, origin, enumname};
|
||||
return Argument {
|
||||
std::move(name),
|
||||
type,
|
||||
optional,
|
||||
std::move(def),
|
||||
std::move(origin),
|
||||
std::move(enumname)};
|
||||
}
|
||||
|
||||
Command parseScheme(executor_func executor, std::string_view description) {
|
||||
@@ -257,9 +263,9 @@ public:
|
||||
CommandsInterpreter* interpreter, Argument* arg
|
||||
) {
|
||||
if (dv::is_numeric(arg->origin)) {
|
||||
return arg->origin;
|
||||
return dv::value(arg->origin);
|
||||
} else if (arg->origin.getType() == dv::value_type::string) {
|
||||
return (*interpreter)[arg->origin.asString()];
|
||||
return dv::value((*interpreter)[arg->origin.asString()]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -296,7 +302,7 @@ public:
|
||||
if (origin == nullptr) {
|
||||
return value;
|
||||
}
|
||||
return applyRelative(arg, value, origin);
|
||||
return applyRelative(arg, std::move(value), origin);
|
||||
}
|
||||
|
||||
inline dv::value performKeywordArg(
|
||||
@@ -378,9 +384,9 @@ public:
|
||||
|
||||
if (relative) {
|
||||
value =
|
||||
applyRelative(arg, value, fetchOrigin(interpreter, arg));
|
||||
applyRelative(arg, std::move(value), fetchOrigin(interpreter, arg));
|
||||
}
|
||||
args.add(value);
|
||||
args.add(std::move(value));
|
||||
}
|
||||
|
||||
while (auto arg = command->getArgument(arg_index++)) {
|
||||
@@ -397,7 +403,7 @@ public:
|
||||
args.add(arg->def);
|
||||
}
|
||||
}
|
||||
return Prompt {command, args, kwargs};
|
||||
return Prompt {command, std::move(args), std::move(kwargs)};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace cmd {
|
||||
};
|
||||
|
||||
using executor_func = std::function<dv::value(
|
||||
CommandsInterpreter*, dv::value args, dv::value kwargs
|
||||
CommandsInterpreter*, const dv::value& args, const dv::value& kwargs
|
||||
)>;
|
||||
|
||||
class Command {
|
||||
|
||||
@@ -96,7 +96,7 @@ static void show_content_missing(
|
||||
contentEntry["type"] = contentName;
|
||||
contentEntry["name"] = entry.name;
|
||||
}
|
||||
menus::show(engine, "reports/missing_content", {root});
|
||||
menus::show(engine, "reports/missing_content", {std::move(root)});
|
||||
}
|
||||
|
||||
static bool loadWorldContent(Engine* engine, const fs::path& folder) {
|
||||
|
||||
@@ -54,7 +54,7 @@ static int l_spawn(lua::State* L) {
|
||||
if (lua::gettop(L) > 2) {
|
||||
args = lua::tovalue(L, 3);
|
||||
}
|
||||
level->entities->spawn(def, pos, args);
|
||||
level->entities->spawn(def, pos, std::move(args));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -340,8 +340,8 @@ void scripting::on_entity_spawn(
|
||||
const EntityDef&,
|
||||
entityid_t eid,
|
||||
const std::vector<std::unique_ptr<UserComponent>>& components,
|
||||
dv::value args,
|
||||
dv::value saved
|
||||
const dv::value& args,
|
||||
const dv::value& saved
|
||||
) {
|
||||
auto L = lua::get_main_thread();
|
||||
lua::requireglobal(L, STDCOMP);
|
||||
|
||||
@@ -94,8 +94,8 @@ namespace scripting {
|
||||
const EntityDef& def,
|
||||
entityid_t eid,
|
||||
const std::vector<std::unique_ptr<UserComponent>>& components,
|
||||
dv::value args,
|
||||
dv::value saved
|
||||
const dv::value& args,
|
||||
const dv::value& saved
|
||||
);
|
||||
void on_entity_despawn(const Entity& entity);
|
||||
void on_entity_grounded(const Entity& entity, float force);
|
||||
|
||||
Reference in New Issue
Block a user