GDScript: Perform validated calls with static methods

When the types are validated at compile time, this type of call runs
faster. It is already used for instance methods, this adds this
optimization to native static methods as well.
This commit is contained in:
George Marques 2024-04-25 21:05:53 -03:00
parent 11d3768132
commit 7ca038effa
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D
9 changed files with 330 additions and 165 deletions

View file

@ -673,7 +673,15 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
} else if (!call->is_super && subscript->base->type == GDScriptParser::Node::IDENTIFIER && call->function_name != SNAME("new") &&
ClassDB::class_exists(static_cast<GDScriptParser::IdentifierNode *>(subscript->base)->name) && !Engine::get_singleton()->has_singleton(static_cast<GDScriptParser::IdentifierNode *>(subscript->base)->name)) {
// It's a static native method call.
gen->write_call_native_static(result, static_cast<GDScriptParser::IdentifierNode *>(subscript->base)->name, subscript->attribute->name, arguments);
StringName class_name = static_cast<GDScriptParser::IdentifierNode *>(subscript->base)->name;
MethodBind *method = ClassDB::get_method(class_name, subscript->attribute->name);
if (_can_use_validate_call(method, arguments)) {
// Exact arguments, use validated call.
gen->write_call_native_static_validated(result, method, arguments);
} else {
// Not exact arguments, use regular static call
gen->write_call_native_static(result, class_name, subscript->attribute->name, arguments);
}
} else {
GDScriptCodeGenerator::Address base = _parse_expression(codegen, r_error, subscript->base);
if (r_error) {