summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2022-05-08 10:09:19 +0200
committerRĂ©mi Verschelde <rverschelde@gmail.com>2022-05-12 11:21:29 +0200
commit8b7c7f5a753b43cec10f72b274bb1d70c253652b (patch)
tree691c51ea7516990b94303afa334d70c66c512cc4 /main
parent9b7e16a6b8b80fe61881e8f4df28550e18050dd2 (diff)
Add a new HashMap implementation
Adds a new, cleaned up, HashMap implementation. * Uses Robin Hood Hashing (https://en.wikipedia.org/wiki/Hash_table#Robin_Hood_hashing). * Keeps elements in a double linked list for simpler, ordered, iteration. * Allows keeping iterators for later use in removal (Unlike Map<>, it does not do much for performance vs keeping the key, but helps replace old code). * Uses a more modern C++ iterator API, deprecates the old one. * Supports custom allocator (in case there is a wish to use a paged one). This class aims to unify all the associative template usage and replace it by this one: * Map<> (whereas key order does not matter, which is 99% of cases) * HashMap<> * OrderedHashMap<> * OAHashMap<>
Diffstat (limited to 'main')
-rw-r--r--main/main.cpp10
-rw-r--r--main/performance.cpp4
-rw-r--r--main/performance.h4
3 files changed, 9 insertions, 9 deletions
diff --git a/main/main.cpp b/main/main.cpp
index 75c4433b41..9747f5aa11 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -2329,11 +2329,11 @@ bool Main::start() {
if (!project_manager && !editor) { // game
if (!game_path.is_empty() || !script.is_empty()) {
//autoload
- OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
+ HashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
//first pass, add the constants so they exist before any script is loaded
- for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
- const ProjectSettings::AutoloadInfo &info = E.get();
+ for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : autoloads) {
+ const ProjectSettings::AutoloadInfo &info = E.value;
if (info.is_singleton) {
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
@@ -2344,8 +2344,8 @@ bool Main::start() {
//second pass, load into global constants
List<Node *> to_add;
- for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
- const ProjectSettings::AutoloadInfo &info = E.get();
+ for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : autoloads) {
+ const ProjectSettings::AutoloadInfo &info = E.value;
Ref<Resource> res = ResourceLoader::load(info.path);
ERR_CONTINUE_MSG(res.is_null(), "Can't autoload: " + info.path);
diff --git a/main/performance.cpp b/main/performance.cpp
index e80906b4a7..25659b999f 100644
--- a/main/performance.cpp
+++ b/main/performance.cpp
@@ -247,8 +247,8 @@ Array Performance::get_custom_monitor_names() {
Array return_array;
return_array.resize(_monitor_map.size());
int index = 0;
- for (OrderedHashMap<StringName, MonitorCall>::Element i = _monitor_map.front(); i; i = i.next()) {
- return_array.set(index, i.key());
+ for (KeyValue<StringName, MonitorCall> i : _monitor_map) {
+ return_array.set(index, i.key);
index++;
}
return return_array;
diff --git a/main/performance.h b/main/performance.h
index 927b5b0389..2837d8f512 100644
--- a/main/performance.h
+++ b/main/performance.h
@@ -32,7 +32,7 @@
#define PERFORMANCE_H
#include "core/object/class_db.h"
-#include "core/templates/ordered_hash_map.h"
+#include "core/templates/hash_map.h"
#define PERF_WARN_OFFLINE_FUNCTION
#define PERF_WARN_PROCESS_SYNC
@@ -58,7 +58,7 @@ class Performance : public Object {
Variant call(bool &r_error, String &r_error_message);
};
- OrderedHashMap<StringName, MonitorCall> _monitor_map;
+ HashMap<StringName, MonitorCall> _monitor_map;
uint64_t _monitor_modification_time;
public: