mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
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:
parent
11d3768132
commit
7ca038effa
9 changed files with 330 additions and 165 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue