diff options
| author | George Marques <george@gmarqu.es> | 2020-11-13 16:47:45 -0300 |
|---|---|---|
| committer | George Marques <george@gmarqu.es> | 2020-11-21 13:24:49 -0300 |
| commit | 1ad5c926dc4d7a182b8621f360b7ce4697dffb25 (patch) | |
| tree | de5daab39985b6203a8aed50089970276a883368 /modules/gdscript/gdscript_vm.cpp | |
| parent | c707d6fe717c43fecafa0aca53182f214268ec16 (diff) | |
| download | redot-engine-1ad5c926dc4d7a182b8621f360b7ce4697dffb25.tar.gz | |
GDScript: Add faster operator for known types
It now uses the direct operator function pointer, which increases
performance in evaluation.
Diffstat (limited to 'modules/gdscript/gdscript_vm.cpp')
| -rw-r--r-- | modules/gdscript/gdscript_vm.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index a10f2a9274..ab923ec37c 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -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); |
