1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

GDScript: Add faster instruction for validated constructor

Only for built-in types.
This commit is contained in:
George Marques
2020-11-18 11:37:08 -03:00
parent e0dca3c6b6
commit 5518e2a68e
5 changed files with 112 additions and 3 deletions

View File

@@ -214,6 +214,7 @@ String GDScriptFunction::_get_call_error(const Callable::CallError &p_err, const
&&OPCODE_CAST_TO_NATIVE, \
&&OPCODE_CAST_TO_SCRIPT, \
&&OPCODE_CONSTRUCT, \
&&OPCODE_CONSTRUCT_VALIDATED, \
&&OPCODE_CONSTRUCT_ARRAY, \
&&OPCODE_CONSTRUCT_DICTIONARY, \
&&OPCODE_CALL, \
@@ -1276,6 +1277,27 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
}
DISPATCH_OPCODE;
OPCODE(OPCODE_CONSTRUCT_VALIDATED) {
CHECK_SPACE(2 + instr_arg_count);
ip += instr_arg_count;
int argc = _code_ptr[ip + 1];
int constructor_idx = _code_ptr[ip + 2];
GD_ERR_BREAK(constructor_idx < 0 || constructor_idx >= _constructors_count);
Variant::ValidatedConstructor constructor = _constructors_ptr[constructor_idx];
Variant **argptrs = instruction_args;
GET_INSTRUCTION_ARG(dst, argc);
constructor(*dst, (const Variant **)argptrs);
ip += 3;
}
DISPATCH_OPCODE;
OPCODE(OPCODE_CONSTRUCT_ARRAY) {
CHECK_SPACE(1 + instr_arg_count);
ip += instr_arg_count;