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_byte_codegen.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_byte_codegen.cpp')
-rw-r--r-- | modules/gdscript/gdscript_byte_codegen.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp index 33e3909e90..cc8790c004 100644 --- a/modules/gdscript/gdscript_byte_codegen.cpp +++ b/modules/gdscript/gdscript_byte_codegen.cpp @@ -158,6 +158,18 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->_default_arg_ptr = nullptr; } + if (operator_func_map.size()) { + function->operator_funcs.resize(operator_func_map.size()); + function->_operator_funcs_count = function->operator_funcs.size(); + function->_operator_funcs_ptr = function->operator_funcs.ptr(); + for (const Map<Variant::ValidatedOperatorEvaluator, int>::Element *E = operator_func_map.front(); E; E = E->next()) { + function->operator_funcs.write[E->get()] = E->key(); + } + } else { + function->_operator_funcs_count = 0; + function->_operator_funcs_ptr = nullptr; + } + if (debug_stack) { function->stack_debug = stack_debug; } @@ -178,7 +190,23 @@ void GDScriptByteCodeGenerator::set_initial_line(int p_line) { function->_initial_line = p_line; } +#define HAS_BUILTIN_TYPE(m_var) \ + (m_var.type.has_type && m_var.type.kind == GDScriptDataType::BUILTIN) + void GDScriptByteCodeGenerator::write_operator(const Address &p_target, Variant::Operator p_operator, const Address &p_left_operand, const Address &p_right_operand) { + if (HAS_BUILTIN_TYPE(p_left_operand) && HAS_BUILTIN_TYPE(p_right_operand)) { + // Gather specific operator. + Variant::ValidatedOperatorEvaluator op_func = Variant::get_validated_operator_evaluator(p_operator, p_left_operand.type.builtin_type, p_right_operand.type.builtin_type); + + append(GDScriptFunction::OPCODE_OPERATOR_VALIDATED, 3); + append(p_left_operand); + append(p_right_operand); + append(p_target); + append(op_func); + return; + } + + // No specific types, perform variant evaluation. append(GDScriptFunction::OPCODE_OPERATOR, 3); append(p_left_operand); append(p_right_operand); |