summaryrefslogtreecommitdiffstats
path: root/modules/gdscript
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-07-18 15:38:29 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-07-18 15:38:29 +0200
commit60966f5bcf9c635c79966a4c16e1af1795331bb3 (patch)
treebf1934f3b552018ad17882079b55881e6e64e2d3 /modules/gdscript
parentcaa1b6d9910a8f75b5135780372b344356db8171 (diff)
parent6852f9497cf14dec69682929ccf574c2e5e83bfd (diff)
downloadredot-engine-60966f5bcf9c635c79966a4c16e1af1795331bb3.tar.gz
Merge pull request #94505 from mihe/speed-up-gdscript-shutdown
Speed up `GDScriptLanguage::finish`
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gdscript.cpp19
-rw-r--r--modules/gdscript/gdscript.h2
2 files changed, 17 insertions, 4 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index 73b1e44db3..eaf2565e69 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -1537,10 +1537,14 @@ void GDScript::clear(ClearData *p_clear_data) {
}
}
- RBSet<GDScript *> must_clear_dependencies = get_must_clear_dependencies();
- for (GDScript *E : must_clear_dependencies) {
- clear_data->scripts.insert(E);
- E->clear(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<GDScript *> 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<StringName, GDScriptFunction *> &E : member_functions) {
@@ -2246,6 +2250,11 @@ String GDScriptLanguage::get_extension() const {
}
void GDScriptLanguage::finish() {
+ if (finishing) {
+ return;
+ }
+ finishing = true;
+
_call_stack.free();
// Clear the cache before parsing the script_list
@@ -2281,6 +2290,8 @@ void GDScriptLanguage::finish() {
}
script_list.clear();
function_list.clear();
+
+ finishing = false;
}
void GDScriptLanguage::profiling_start() {
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index d097cb193b..4e78fbe302 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -411,6 +411,8 @@ class GDScriptLanguage : public ScriptLanguage {
static GDScriptLanguage *singleton;
+ bool finishing = false;
+
Variant *_global_array = nullptr;
Vector<Variant> global_array;
HashMap<StringName, int> globals;