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

GDScript: Add faster operator for known types

It now uses the direct operator function pointer, which increases
performance in evaluation.
This commit is contained in:
George Marques
2020-11-13 16:47:45 -03:00
parent c707d6fe71
commit 1ad5c926dc
5 changed files with 77 additions and 3 deletions

View File

@@ -188,6 +188,7 @@ String GDScriptFunction::_get_call_error(const Callable::CallError &p_err, const
#define OPCODES_TABLE \
static const void *switch_table_ops[] = { \
&&OPCODE_OPERATOR, \
&&OPCODE_OPERATOR_VALIDATED, \
&&OPCODE_EXTENDS_TEST, \
&&OPCODE_IS_BUILTIN, \
&&OPCODE_SET, \
@@ -468,6 +469,23 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
}
DISPATCH_OPCODE;
OPCODE(OPCODE_OPERATOR_VALIDATED) {
CHECK_SPACE(5);
int operator_idx = _code_ptr[ip + 4];
GD_ERR_BREAK(operator_idx < 0 || operator_idx >= _operator_funcs_count);
Variant::ValidatedOperatorEvaluator operator_func = _operator_funcs_ptr[operator_idx];
GET_INSTRUCTION_ARG(a, 0);
GET_INSTRUCTION_ARG(b, 1);
GET_INSTRUCTION_ARG(dst, 2);
operator_func(a, b, dst);
ip += 5;
}
DISPATCH_OPCODE;
OPCODE(OPCODE_EXTENDS_TEST) {
CHECK_SPACE(4);