Merge pull request #1176 from dsnopek/string-name-allocate-once

In generated methods, only allocate the method StringName the first time
pull/1181/head
David Snopek 2023-07-22 09:04:13 -05:00 committed by GitHub
commit ef5a185dc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 7 deletions

View File

@ -1453,9 +1453,8 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
if is_singleton: if is_singleton:
result.append(f"{class_name} *{class_name}::get_singleton() {{") result.append(f"{class_name} *{class_name}::get_singleton() {{")
result.append(f"\tconst StringName _gde_class_name = {class_name}::get_class_static();")
result.append( result.append(
"\tstatic GDExtensionObjectPtr singleton_obj = internal::gdextension_interface_global_get_singleton(_gde_class_name._native_ptr());" f"\tstatic GDExtensionObjectPtr singleton_obj = internal::gdextension_interface_global_get_singleton({class_name}::get_class_static()._native_ptr());"
) )
result.append("#ifdef DEBUG_ENABLED") result.append("#ifdef DEBUG_ENABLED")
result.append("\tERR_FAIL_COND_V(singleton_obj == nullptr, nullptr);") result.append("\tERR_FAIL_COND_V(singleton_obj == nullptr, nullptr);")
@ -1480,10 +1479,8 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
result.append(method_signature + " {") result.append(method_signature + " {")
# Method body. # Method body.
result.append(f"\tconst StringName _gde_class_name = {class_name}::get_class_static();")
result.append(f'\tconst StringName _gde_method_name = "{method["name"]}";')
result.append( result.append(
f'\tstatic GDExtensionMethodBindPtr _gde_method_bind = internal::gdextension_interface_classdb_get_method_bind(_gde_class_name._native_ptr(), _gde_method_name._native_ptr(), {method["hash"]});' f'\tstatic GDExtensionMethodBindPtr _gde_method_bind = internal::gdextension_interface_classdb_get_method_bind({class_name}::get_class_static()._native_ptr(), StringName("{method["name"]}")._native_ptr(), {method["hash"]});'
) )
method_call = "\t" method_call = "\t"
has_return = "return_value" in method and method["return_value"]["type"] != "void" has_return = "return_value" in method and method["return_value"]["type"] != "void"
@ -1773,9 +1770,8 @@ def generate_utility_functions(api, output_dir):
# Function body. # Function body.
source.append(f'\tconst StringName _gde_function_name = "{function["name"]}";')
source.append( source.append(
f'\tstatic GDExtensionPtrUtilityFunction _gde_function = internal::gdextension_interface_variant_get_ptr_utility_function(_gde_function_name._native_ptr(), {function["hash"]});' f'\tstatic GDExtensionPtrUtilityFunction _gde_function = internal::gdextension_interface_variant_get_ptr_utility_function(StringName("{function["name"]}")._native_ptr(), {function["hash"]});'
) )
has_return = "return_type" in function and function["return_type"] != "void" has_return = "return_type" in function and function["return_type"] != "void"
if has_return: if has_return: