You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Mono/C#: Optimize the way we store GC handles for scripts
Don't store GC handles for C# script instances and instance bindings as 'Ref<MonoGCHandle>'; store the raw data instead. Initially this was not possible as we needed to store a Variant, but this had not been the case for a looong time yet the stored type was never updated.
This commit is contained in:
@@ -86,10 +86,9 @@ MonoObject *unmanaged_get_managed(Object *unmanaged) {
|
||||
}
|
||||
}
|
||||
|
||||
Ref<MonoGCHandle> &gchandle = script_binding.gchandle;
|
||||
ERR_FAIL_COND_V(gchandle.is_null(), NULL);
|
||||
MonoGCHandleData &gchandle = script_binding.gchandle;
|
||||
|
||||
MonoObject *target = gchandle->get_target();
|
||||
MonoObject *target = gchandle.get_target();
|
||||
|
||||
if (target)
|
||||
return target;
|
||||
@@ -106,7 +105,7 @@ MonoObject *unmanaged_get_managed(Object *unmanaged) {
|
||||
MonoObject *mono_object = GDMonoUtils::create_managed_for_godot_object(script_binding.wrapper_class, script_binding.type_name, unmanaged);
|
||||
ERR_FAIL_NULL_V(mono_object, NULL);
|
||||
|
||||
gchandle->set_handle(MonoGCHandle::new_strong_handle(mono_object), MonoGCHandle::STRONG_HANDLE);
|
||||
gchandle = MonoGCHandleData::new_strong_handle(mono_object);
|
||||
|
||||
// Tie managed to unmanaged
|
||||
Reference *ref = Object::cast_to<Reference>(unmanaged);
|
||||
@@ -156,6 +155,22 @@ bool is_thread_attached() {
|
||||
return mono_domain_get() != NULL;
|
||||
}
|
||||
|
||||
uint32_t new_strong_gchandle(MonoObject *p_object) {
|
||||
return mono_gchandle_new(p_object, /* pinned: */ false);
|
||||
}
|
||||
|
||||
uint32_t new_strong_gchandle_pinned(MonoObject *p_object) {
|
||||
return mono_gchandle_new(p_object, /* pinned: */ true);
|
||||
}
|
||||
|
||||
uint32_t new_weak_gchandle(MonoObject *p_object) {
|
||||
return mono_gchandle_new_weakref(p_object, /* track_resurrection: */ false);
|
||||
}
|
||||
|
||||
void free_gchandle(uint32_t p_gchandle) {
|
||||
mono_gchandle_free(p_gchandle);
|
||||
}
|
||||
|
||||
void runtime_object_init(MonoObject *p_this_obj, GDMonoClass *p_class, MonoException **r_exc) {
|
||||
GDMonoMethod *ctor = p_class->get_method(".ctor", 0);
|
||||
ERR_FAIL_NULL(ctor);
|
||||
|
||||
Reference in New Issue
Block a user