From 45af29da8095af16729955117a165d23e77cd740 Mon Sep 17 00:00:00 2001 From: reduz Date: Thu, 19 May 2022 17:00:06 +0200 Subject: Add a new HashSet template * Intended to replace RBSet in most cases. * Optimized for iteration speed --- modules/mono/csharp_script.cpp | 18 +++++++++--------- modules/mono/csharp_script.h | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'modules/mono') diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index d0140f117c..bee4e0e1fb 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -875,7 +875,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { // Script::instances are deleted during managed object disposal, which happens on domain finalize. // Only placeholders are kept. Therefore we need to keep a copy before that happens. - for (Object *&obj : script->instances) { + for (Object *obj : script->instances) { script->pending_reload_instances.insert(obj->get_instance_id()); RefCounted *rc = Object::cast_to(obj); @@ -885,7 +885,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { } #ifdef TOOLS_ENABLED - for (PlaceHolderScriptInstance *&script_instance : script->placeholders) { + for (PlaceHolderScriptInstance *script_instance : script->placeholders) { Object *obj = script_instance->get_owner(); script->pending_reload_instances.insert(obj->get_instance_id()); @@ -899,7 +899,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { // Save state and remove script from instances RBMap &owners_map = script->pending_reload_state; - for (Object *&obj : script->instances) { + for (Object *obj : script->instances) { ERR_CONTINUE(!obj->get_script_instance()); CSharpInstance *csi = static_cast(obj->get_script_instance()); @@ -922,8 +922,8 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { // After the state of all instances is saved, clear scripts and script instances for (Ref &script : scripts) { - while (script->instances.front()) { - Object *obj = script->instances.front()->get(); + while (script->instances.begin()) { + Object *obj = *script->instances.begin(); obj->set_script(Ref()); // Remove script and existing script instances (placeholder are not removed before domain reload) } @@ -2315,9 +2315,9 @@ CSharpInstance::~CSharpInstance() { #ifdef DEBUG_ENABLED // CSharpInstance must not be created unless it's going to be added to the list for sure - RBSet::Element *match = script->instances.find(owner); + HashSet::Iterator match = script->instances.find(owner); CRASH_COND(!match); - script->instances.erase(match); + script->instances.remove(match); #else script->instances.erase(owner); #endif @@ -2572,7 +2572,7 @@ bool CSharpScript::_update_exports(PlaceHolderScriptInstance *p_instance_to_upda _update_exports_values(values, propnames); if (changed) { - for (PlaceHolderScriptInstance *&script_instance : placeholders) { + for (PlaceHolderScriptInstance *script_instance : placeholders) { script_instance->update(propnames, values); } } else { @@ -3574,7 +3574,7 @@ CSharpScript::~CSharpScript() { #endif } -void CSharpScript::get_members(RBSet *p_members) { +void CSharpScript::get_members(HashSet *p_members) { #if defined(TOOLS_ENABLED) || defined(DEBUG_ENABLED) if (p_members) { for (const StringName &member_name : exported_members_names) { diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h index 6e600bb47a..69bd8703aa 100644 --- a/modules/mono/csharp_script.h +++ b/modules/mono/csharp_script.h @@ -110,7 +110,7 @@ private: Ref base_cache; // TODO what's this for? - RBSet instances; + HashSet instances; #ifdef GD_MONO_HOT_RELOAD struct StateBackup { @@ -121,7 +121,7 @@ private: List> event_signals; }; - RBSet pending_reload_instances; + HashSet pending_reload_instances; RBMap pending_reload_state; StringName tied_class_name_for_reload; StringName tied_class_namespace_for_reload; @@ -141,7 +141,7 @@ private: #ifdef TOOLS_ENABLED List exported_members_cache; // members_cache HashMap exported_members_defval_cache; // member_default_values_cache - RBSet placeholders; + HashSet placeholders; bool source_changed_cache = false; bool placeholder_fallback_enabled = false; bool exports_invalidated = true; @@ -151,7 +151,7 @@ private: #endif #if defined(TOOLS_ENABLED) || defined(DEBUG_ENABLED) - RBSet exported_members_names; + HashSet exported_members_names; #endif HashMap member_info; @@ -218,7 +218,7 @@ public: void get_script_property_list(List *r_list) const override; void update_exports() override; - void get_members(RBSet *p_members) override; + void get_members(HashSet *p_members) override; bool is_tool() const override { return tool; } bool is_valid() const override { return valid; } @@ -467,7 +467,7 @@ public: virtual Ref