From 7ca038effa28c1767e43e4f66d2bd9f34852d5b7 Mon Sep 17 00:00:00 2001 From: George Marques Date: Thu, 25 Apr 2024 21:05:53 -0300 Subject: 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. --- modules/gdscript/gdscript_compiler.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'modules/gdscript/gdscript_compiler.cpp') diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 734e37bc09..a8a7f3d9f7 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -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(subscript->base)->name) && !Engine::get_singleton()->has_singleton(static_cast(subscript->base)->name)) { // It's a static native method call. - gen->write_call_native_static(result, static_cast(subscript->base)->name, subscript->attribute->name, arguments); + StringName class_name = static_cast(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) { -- cgit v1.2.3