diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index c75a70d3beaa..8b133961ae6a 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1261,69 +1261,6 @@ GDScript *GDScript::get_root_script() { return result; } -RBSet GDScript::get_dependencies() { - RBSet dependencies; - - _collect_dependencies(dependencies, this); - dependencies.erase(this); - - return dependencies; -} - -HashMap> GDScript::get_all_dependencies() { - HashMap> all_dependencies; - - List scripts; - { - MutexLock lock(GDScriptLanguage::singleton->mutex); - - SelfList *elem = GDScriptLanguage::singleton->script_list.first(); - while (elem) { - scripts.push_back(elem->self()); - elem = elem->next(); - } - } - - for (GDScript *scr : scripts) { - if (scr == nullptr || scr->destructing) { - continue; - } - all_dependencies.insert(scr, scr->get_dependencies()); - } - - return all_dependencies; -} - -RBSet GDScript::get_must_clear_dependencies() { - RBSet dependencies = get_dependencies(); - RBSet must_clear_dependencies; - HashMap> all_dependencies = get_all_dependencies(); - - RBSet cant_clear; - for (KeyValue> &E : all_dependencies) { - if (dependencies.has(E.key)) { - continue; - } - for (GDScript *F : E.value) { - if (dependencies.has(F)) { - cant_clear.insert(F); - } - } - } - - for (GDScript *E : dependencies) { - if (cant_clear.has(E) || ScriptServer::is_global_class(E->get_fully_qualified_name())) { - continue; - } - must_clear_dependencies.insert(E); - } - - cant_clear.clear(); - dependencies.clear(); - all_dependencies.clear(); - return must_clear_dependencies; -} - bool GDScript::has_script_signal(const StringName &p_signal) const { if (_signals.has(p_signal)) { return true; @@ -1362,67 +1299,6 @@ void GDScript::get_script_signal_list(List *r_signals) const { _get_script_signal_list(r_signals, true); } -GDScript *GDScript::_get_gdscript_from_variant(const Variant &p_variant) { - Object *obj = p_variant; - if (obj == nullptr || obj->get_instance_id().is_null()) { - return nullptr; - } - return Object::cast_to(obj); -} - -void GDScript::_collect_function_dependencies(GDScriptFunction *p_func, RBSet &p_dependencies, const GDScript *p_except) { - if (p_func == nullptr) { - return; - } - for (GDScriptFunction *lambda : p_func->lambdas) { - _collect_function_dependencies(lambda, p_dependencies, p_except); - } - for (const Variant &V : p_func->constants) { - GDScript *scr = _get_gdscript_from_variant(V); - if (scr != nullptr && scr != p_except) { - scr->_collect_dependencies(p_dependencies, p_except); - } - } -} - -void GDScript::_collect_dependencies(RBSet &p_dependencies, const GDScript *p_except) { - if (p_dependencies.has(this)) { - return; - } - if (this != p_except) { - p_dependencies.insert(this); - } - - for (const KeyValue &E : member_functions) { - _collect_function_dependencies(E.value, p_dependencies, p_except); - } - - if (implicit_initializer) { - _collect_function_dependencies(implicit_initializer, p_dependencies, p_except); - } - - if (implicit_ready) { - _collect_function_dependencies(implicit_ready, p_dependencies, p_except); - } - - if (static_initializer) { - _collect_function_dependencies(static_initializer, p_dependencies, p_except); - } - - for (KeyValue> &E : subclasses) { - if (E.value != p_except) { - E.value->_collect_dependencies(p_dependencies, p_except); - } - } - - for (const KeyValue &E : constants) { - GDScript *scr = _get_gdscript_from_variant(E.value); - if (scr != nullptr && scr != p_except) { - scr->_collect_dependencies(p_dependencies, p_except); - } - } -} - GDScript::GDScript() : script_list(this) { { @@ -1434,7 +1310,7 @@ GDScript::GDScript() : path = vformat("gdscript://%d.gd", get_instance_id()); } -void GDScript::_save_orphaned_subclasses(ClearData *p_clear_data) { +void GDScript::_save_orphaned_subclasses() { struct ClassRefWithName { ObjectID id; String fully_qualified_name; @@ -1450,17 +1326,8 @@ void GDScript::_save_orphaned_subclasses(ClearData *p_clear_data) { } // clear subclasses to allow unused subclasses to be deleted - for (KeyValue> &E : subclasses) { - p_clear_data->scripts.insert(E.value); - } subclasses.clear(); // subclasses are also held by constants, clear those as well - for (KeyValue &E : constants) { - GDScript *gdscr = _get_gdscript_from_variant(E.value); - if (gdscr != nullptr) { - p_clear_data->scripts.insert(gdscr); - } - } constants.clear(); // keep orphan subclass only for subclasses that are still in use @@ -1546,22 +1413,13 @@ void GDScript::_recurse_replace_function_ptrs(const HashMap functions_to_clear; { MutexLock lock(func_ptrs_to_update_mutex); @@ -1570,49 +1428,35 @@ void GDScript::clear(ClearData *p_clear_data) { } } - // If we're in the process of shutting things down then every single script will be cleared - // anyway, so we can safely skip this very costly operation. - if (!GDScriptLanguage::singleton->finishing) { - RBSet must_clear_dependencies = get_must_clear_dependencies(); - for (GDScript *E : must_clear_dependencies) { - clear_data->scripts.insert(E); - E->clear(clear_data); - } - } - for (const KeyValue &E : member_functions) { - clear_data->functions.insert(E.value); + functions_to_clear.insert(E.value); } member_functions.clear(); for (KeyValue &E : member_indices) { - clear_data->scripts.insert(E.value.data_type.script_type_ref); E.value.data_type.script_type_ref = Ref