You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
GDScript: Optimize operators by assuming the types
This assumes that operators are called usually with the same type of operands as the first time. So it stores the types of the first run and if matched it uses an optimized path by calling the validated operator function directly. Otherwise it uses the regular untyped evaluator. With this change, if operators do use the same type they run quite faster. OTOH, if the types mismatch it takes longer to run than they would with the previous code.
This commit is contained in:
@@ -226,7 +226,7 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() {
|
||||
|
||||
if (opcodes.size()) {
|
||||
function->code = opcodes;
|
||||
function->_code_ptr = &function->code[0];
|
||||
function->_code_ptr = &function->code.write[0];
|
||||
function->_code_size = opcodes.size();
|
||||
|
||||
} else {
|
||||
@@ -577,6 +577,12 @@ void GDScriptByteCodeGenerator::write_unary_operator(const Address &p_target, Va
|
||||
append(Address());
|
||||
append(p_target);
|
||||
append(p_operator);
|
||||
append(0); // Signature storage.
|
||||
append(0); // Return type storage.
|
||||
constexpr int _pointer_size = sizeof(Variant::ValidatedOperatorEvaluator) / sizeof(*(opcodes.ptr()));
|
||||
for (int i = 0; i < _pointer_size; i++) {
|
||||
append(0); // Space for function pointer.
|
||||
}
|
||||
}
|
||||
|
||||
void GDScriptByteCodeGenerator::write_binary_operator(const Address &p_target, Variant::Operator p_operator, const Address &p_left_operand, const Address &p_right_operand) {
|
||||
@@ -610,6 +616,12 @@ void GDScriptByteCodeGenerator::write_binary_operator(const Address &p_target, V
|
||||
append(p_right_operand);
|
||||
append(p_target);
|
||||
append(p_operator);
|
||||
append(0); // Signature storage.
|
||||
append(0); // Return type storage.
|
||||
constexpr int _pointer_size = sizeof(Variant::ValidatedOperatorEvaluator) / sizeof(*(opcodes.ptr()));
|
||||
for (int i = 0; i < _pointer_size; i++) {
|
||||
append(0); // Space for function pointer.
|
||||
}
|
||||
}
|
||||
|
||||
void GDScriptByteCodeGenerator::write_type_test(const Address &p_target, const Address &p_source, const GDScriptDataType &p_type) {
|
||||
|
||||
Reference in New Issue
Block a user