summaryrefslogtreecommitdiff
path: root/core/config
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2022-05-13 15:04:37 +0200
committerRĂ©mi Verschelde <rverschelde@gmail.com>2022-05-16 10:37:48 +0200
commit746dddc0673d7261f19b1e056e90e6e3a49ef33a (patch)
tree434b526eb286850ebccc6d2c998a7d90fdb8b5e2 /core/config
parent396def9b66c476f7834604adb7136ca903ed01be (diff)
Replace most uses of Map by HashMap
* Map is unnecessary and inefficient in almost every case. * Replaced by the new HashMap. * Renamed Map to RBMap and Set to RBSet for cases that still make sense (order matters) but use is discouraged. There were very few cases where replacing by HashMap was undesired because keeping the key order was intended. I tried to keep those (as RBMap) as much as possible, but might have missed some. Review appreciated!
Diffstat (limited to 'core/config')
-rw-r--r--core/config/engine.cpp4
-rw-r--r--core/config/engine.h2
-rw-r--r--core/config/project_settings.cpp51
-rw-r--r--core/config/project_settings.h18
4 files changed, 38 insertions, 37 deletions
diff --git a/core/config/engine.cpp b/core/config/engine.cpp
index ff8a8d283f..782d369ae6 100644
--- a/core/config/engine.cpp
+++ b/core/config/engine.cpp
@@ -208,9 +208,9 @@ void Engine::add_singleton(const Singleton &p_singleton) {
}
Object *Engine::get_singleton_object(const StringName &p_name) const {
- const Map<StringName, Object *>::Element *E = singleton_ptrs.find(p_name);
+ HashMap<StringName, Object *>::ConstIterator E = singleton_ptrs.find(p_name);
ERR_FAIL_COND_V_MSG(!E, nullptr, "Failed to retrieve non-existent singleton '" + String(p_name) + "'.");
- return E->get();
+ return E->value;
}
bool Engine::is_singleton_user_created(const StringName &p_name) const {
diff --git a/core/config/engine.h b/core/config/engine.h
index eac96852b3..82e3ee5487 100644
--- a/core/config/engine.h
+++ b/core/config/engine.h
@@ -69,7 +69,7 @@ private:
bool _in_physics = false;
List<Singleton> singletons;
- Map<StringName, Object *> singleton_ptrs;
+ HashMap<StringName, Object *> singleton_ptrs;
bool editor_hint = false;
bool project_manager_hint = false;
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp
index ba108d75da..3ef9a69d06 100644
--- a/core/config/project_settings.cpp
+++ b/core/config/project_settings.cpp
@@ -331,7 +331,7 @@ struct _VCSort {
void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
_THREAD_SAFE_METHOD_
- Set<_VCSort> vclist;
+ RBSet<_VCSort> vclist;
for (const KeyValue<StringName, VariantContainer> &E : props) {
const VariantContainer *v = &E.value;
@@ -360,7 +360,7 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
vclist.insert(vc);
}
- for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
+ for (RBSet<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
String prop_info_name = E->get().name;
int dot = prop_info_name.find(".");
if (dot != -1 && !custom_prop_info.has(prop_info_name)) {
@@ -764,7 +764,7 @@ Error ProjectSettings::save() {
return error;
}
-Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
+Error ProjectSettings::_save_settings_binary(const String &p_file, const HashMap<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
Error err;
Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.binary at " + p_file + ".");
@@ -800,19 +800,20 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str
file->store_32(count); //store how many properties are saved
}
- for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
- for (String &key : E->get()) {
- if (!E->key().is_empty()) {
- key = E->key() + "/" + key;
+ for (const KeyValue<String, List<String>> &E : props) {
+ for (const String &key : E.value) {
+ String k = key;
+ if (!E.key.is_empty()) {
+ k = E.key + "/" + k;
}
Variant value;
- if (p_custom.has(key)) {
- value = p_custom[key];
+ if (p_custom.has(k)) {
+ value = p_custom[k];
} else {
- value = get(key);
+ value = get(k);
}
- file->store_pascal_string(key);
+ file->store_pascal_string(k);
int len;
err = encode_variant(value, nullptr, len, true);
@@ -831,7 +832,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str
return OK;
}
-Error ProjectSettings::_save_settings_text(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
+Error ProjectSettings::_save_settings_text(const String &p_file, const HashMap<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
Error err;
Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
@@ -852,18 +853,18 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin
}
file->store_string("\n");
- for (const Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
- if (E != props.front()) {
+ for (const KeyValue<String, List<String>> &E : props) {
+ if (E.key != props.begin()->key) {
file->store_string("\n");
}
- if (!E->key().is_empty()) {
- file->store_string("[" + E->key() + "]\n\n");
+ if (!E.key.is_empty()) {
+ file->store_string("[" + E.key + "]\n\n");
}
- for (const String &F : E->get()) {
+ for (const String &F : E.value) {
String key = F;
- if (!E->key().is_empty()) {
- key = E->key() + "/" + key;
+ if (!E.key.is_empty()) {
+ key = E.key + "/" + key;
}
Variant value;
if (p_custom.has(key)) {
@@ -917,7 +918,7 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
project_features = _trim_to_supported_features(project_features);
set_setting("application/config/features", project_features);
- Set<_VCSort> vclist;
+ RBSet<_VCSort> vclist;
if (p_merge_with_current) {
for (const KeyValue<StringName, VariantContainer> &G : props) {
@@ -946,19 +947,19 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
for (const KeyValue<String, Variant> &E : p_custom) {
// Lookup global prop to store in the same order
- Map<StringName, VariantContainer>::Element *global_prop = props.find(E.key);
+ HashMap<StringName, VariantContainer>::Iterator global_prop = props.find(E.key);
_VCSort vc;
vc.name = E.key;
- vc.order = global_prop ? global_prop->get().order : 0xFFFFFFF;
+ vc.order = global_prop ? global_prop->value.order : 0xFFFFFFF;
vc.type = E.value.get_type();
vc.flags = PROPERTY_USAGE_STORAGE;
vclist.insert(vc);
}
- Map<String, List<String>> props;
+ HashMap<String, List<String>> props;
- for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
+ for (RBSet<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
String category = E->get().name;
String name = E->get().name;
@@ -1051,7 +1052,7 @@ void ProjectSettings::set_custom_property_info(const String &p_prop, const Prope
custom_prop_info[p_prop].name = p_prop;
}
-const Map<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
+const HashMap<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
return custom_prop_info;
}
diff --git a/core/config/project_settings.h b/core/config/project_settings.h
index 8655526edd..f8dc618cb8 100644
--- a/core/config/project_settings.h
+++ b/core/config/project_settings.h
@@ -34,14 +34,14 @@
#include "core/object/class_db.h"
#include "core/os/thread_safe.h"
#include "core/templates/hash_map.h"
-#include "core/templates/set.h"
+#include "core/templates/rb_set.h"
class ProjectSettings : public Object {
GDCLASS(ProjectSettings, Object);
_THREAD_SAFE_CLASS_
public:
- typedef Map<String, Variant> CustomMap;
+ typedef HashMap<String, Variant> CustomMap;
static const String PROJECT_DATA_DIR_NAME_SUFFIX;
enum {
@@ -84,15 +84,15 @@ protected:
int last_builtin_order = 0;
uint64_t last_save_time = 0;
- Map<StringName, VariantContainer> props;
+ HashMap<StringName, VariantContainer> props;
String resource_path;
- Map<StringName, PropertyInfo> custom_prop_info;
+ HashMap<StringName, PropertyInfo> custom_prop_info;
bool disable_feature_overrides = false;
bool using_datapack = false;
List<String> input_presets;
- Set<String> custom_features;
- Map<StringName, StringName> feature_overrides;
+ RBSet<String> custom_features;
+ HashMap<StringName, StringName> feature_overrides;
HashMap<StringName, AutoloadInfo> autoloads;
@@ -108,8 +108,8 @@ protected:
Error _load_settings_binary(const String &p_path);
Error _load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path);
- Error _save_settings_text(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String());
- Error _save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String());
+ Error _save_settings_text(const String &p_file, const HashMap<String, List<String>> &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String());
+ Error _save_settings_binary(const String &p_file, const HashMap<String, List<String>> &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String());
Error _save_custom_bnd(const String &p_file);
@@ -168,7 +168,7 @@ public:
Error save_custom(const String &p_path = "", const CustomMap &p_custom = CustomMap(), const Vector<String> &p_custom_features = Vector<String>(), bool p_merge_with_current = true);
Error save();
void set_custom_property_info(const String &p_prop, const PropertyInfo &p_info);
- const Map<StringName, PropertyInfo> &get_custom_property_info() const;
+ const HashMap<StringName, PropertyInfo> &get_custom_property_info() const;
uint64_t get_last_saved_time() { return last_save_time; }
Vector<String> get_optimizer_presets() const;