minimize extra dv::value copies
This commit is contained in:
parent
bd176f24e1
commit
3953583605
@ -225,7 +225,7 @@ static void read_anim_file(
|
||||
if (auto found = root.at("frames")) {
|
||||
auto& frameArr = *found;
|
||||
for (size_t i = 0; i < frameArr.size(); i++) {
|
||||
auto currentFrame = frameArr[i];
|
||||
const auto& currentFrame = frameArr[i];
|
||||
|
||||
frameName = currentFrame[0].asString();
|
||||
if (currentFrame.size() > 1) {
|
||||
|
||||
@ -114,7 +114,7 @@ static dv::value value_from_binary(ByteReader& reader) {
|
||||
case BJSON_TYPE_STRING:
|
||||
return reader.getString();
|
||||
case BJSON_TYPE_NULL:
|
||||
return dv::none;
|
||||
return nullptr;
|
||||
case BJSON_TYPE_BYTES: {
|
||||
int32_t size = reader.getInt32();
|
||||
if (size < 0) {
|
||||
|
||||
@ -102,10 +102,10 @@ public:
|
||||
dv::value read() {
|
||||
skipWhitespace();
|
||||
if (!hasNext()) {
|
||||
return root;
|
||||
return std::move(root);
|
||||
}
|
||||
readSection("", root);
|
||||
return root;
|
||||
return std::move(root);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -148,7 +148,7 @@ public:
|
||||
return MISSING;
|
||||
}
|
||||
|
||||
dv::value getSavedData(size_t index) const {
|
||||
const dv::value& getSavedData(size_t index) const {
|
||||
return savedData->at(index);
|
||||
}
|
||||
|
||||
|
||||
@ -504,8 +504,6 @@ namespace dv {
|
||||
}
|
||||
};
|
||||
|
||||
inline value none = value();
|
||||
|
||||
inline bool is_numeric(const value& val) {
|
||||
return val.isInteger() && val.isNumber();
|
||||
}
|
||||
|
||||
@ -477,11 +477,11 @@ dv::value WorldRegions::fetchEntities(int x, int z) {
|
||||
uint32_t bytesSize;
|
||||
const ubyte* data = getData(x, z, REGION_LAYER_ENTITIES, bytesSize);
|
||||
if (data == nullptr) {
|
||||
return dv::none;
|
||||
return nullptr;
|
||||
}
|
||||
auto map = json::from_binary(data, bytesSize);
|
||||
if (map.size() == 0) {
|
||||
return dv::none;
|
||||
return nullptr;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -173,8 +173,7 @@ entityid_t Entities::spawn(
|
||||
}
|
||||
body.hitbox.position = tsf.pos;
|
||||
scripting::on_entity_spawn(
|
||||
def, id, scripting.components, std::move(args), std::move(componentsMap)
|
||||
);
|
||||
def, id, scripting.components, args, componentsMap);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@ -167,7 +167,7 @@ std::unique_ptr<SkeletonConfig> SkeletonConfig::parse(
|
||||
std::string_view src, std::string_view file, std::string_view name
|
||||
) {
|
||||
auto root = json::parse(file, src);
|
||||
auto rootNodeMap = root["root"];
|
||||
const auto& rootNodeMap = root["root"];
|
||||
auto [count, rootNode] = read_node(rootNodeMap, 0);
|
||||
return std::make_unique<SkeletonConfig>(
|
||||
std::string(name), std::move(rootNode), count
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user