MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / get_instance_binding

Method get_instance_binding

core/object/object.cpp:2116–2150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2114}
2115
2116void *Object::get_instance_binding(void *p_token, const GDExtensionInstanceBindingCallbacks *p_callbacks) {
2117 void *binding = nullptr;
2118 MutexLock instance_binding_lock(_instance_binding_mutex);
2119 for (uint32_t i = 0; i < _instance_binding_count; i++) {
2120 if (_instance_bindings[i].token == p_token) {
2121 binding = _instance_bindings[i].binding;
2122 break;
2123 }
2124 }
2125 if (unlikely(!binding && p_callbacks)) {
2126 uint32_t current_size = next_power_of_2(_instance_binding_count);
2127 uint32_t new_size = next_power_of_2(_instance_binding_count + 1);
2128
2129 if (current_size == 0 || new_size > current_size) {
2130 _instance_bindings = (InstanceBinding *)memrealloc(_instance_bindings, new_size * sizeof(InstanceBinding));
2131 }
2132
2133 _instance_bindings[_instance_binding_count].free_callback = p_callbacks->free_callback;
2134 _instance_bindings[_instance_binding_count].reference_callback = p_callbacks->reference_callback;
2135 _instance_bindings[_instance_binding_count].token = p_token;
2136
2137 binding = p_callbacks->create_callback(p_token, this);
2138 _instance_bindings[_instance_binding_count].binding = binding;
2139
2140#ifdef TOOLS_ENABLED
2141 if (!_extension && Engine::get_singleton()->is_extension_reloading_enabled()) {
2142 GDExtensionManager::get_singleton()->track_instance_binding(p_token, this);
2143 }
2144#endif
2145
2146 _instance_binding_count++;
2147 }
2148
2149 return binding;
2150}
2151
2152bool Object::has_instance_binding(void *p_token) {
2153 bool found = false;

Calls 4

next_power_of_2Function · 0.85
create_callbackMethod · 0.45

Tested by

no test coverage detected