1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

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!
This commit is contained in:
reduz
2022-05-13 15:04:37 +02:00
committed by Rémi Verschelde
parent 396def9b66
commit 746dddc067
587 changed files with 3707 additions and 3538 deletions

View File

@@ -68,7 +68,7 @@ bool SceneDebugger::RPCProfilerFrame::deserialize(const Array &p_arr) {
}
class SceneDebugger::RPCProfiler : public EngineProfiler {
Map<ObjectID, RPCNodeInfo> rpc_node_data;
HashMap<ObjectID, RPCNodeInfo> rpc_node_data;
uint64_t last_profile_time = 0;
void init_node(const ObjectID p_node) {
@@ -345,22 +345,22 @@ void SceneDebugger::remove_from_cache(const String &p_filename, Node *p_node) {
return;
}
Map<String, Set<Node *>> &edit_cache = debugger->live_scene_edit_cache;
Map<String, Set<Node *>>::Element *E = edit_cache.find(p_filename);
HashMap<String, RBSet<Node *>> &edit_cache = debugger->live_scene_edit_cache;
HashMap<String, RBSet<Node *>>::Iterator E = edit_cache.find(p_filename);
if (E) {
E->get().erase(p_node);
if (E->get().size() == 0) {
edit_cache.erase(E);
E->value.erase(p_node);
if (E->value.size() == 0) {
edit_cache.remove(E);
}
}
Map<Node *, Map<ObjectID, Node *>> &remove_list = debugger->live_edit_remove_list;
Map<Node *, Map<ObjectID, Node *>>::Element *F = remove_list.find(p_node);
HashMap<Node *, HashMap<ObjectID, Node *>> &remove_list = debugger->live_edit_remove_list;
HashMap<Node *, HashMap<ObjectID, Node *>>::Iterator F = remove_list.find(p_node);
if (F) {
for (const KeyValue<ObjectID, Node *> &G : F->get()) {
for (const KeyValue<ObjectID, Node *> &G : F->value) {
memdelete(G.value);
}
remove_list.erase(F);
remove_list.remove(F);
}
}
@@ -408,47 +408,47 @@ SceneDebuggerObject::SceneDebuggerObject(ObjectID p_id) {
}
void SceneDebuggerObject::_parse_script_properties(Script *p_script, ScriptInstance *p_instance) {
typedef Map<const Script *, Set<StringName>> ScriptMemberMap;
typedef Map<const Script *, Map<StringName, Variant>> ScriptConstantsMap;
typedef HashMap<const Script *, RBSet<StringName>> ScriptMemberMap;
typedef HashMap<const Script *, HashMap<StringName, Variant>> ScriptConstantsMap;
ScriptMemberMap members;
if (p_instance) {
members[p_script] = Set<StringName>();
members[p_script] = RBSet<StringName>();
p_script->get_members(&(members[p_script]));
}
ScriptConstantsMap constants;
constants[p_script] = Map<StringName, Variant>();
constants[p_script] = HashMap<StringName, Variant>();
p_script->get_constants(&(constants[p_script]));
Ref<Script> base = p_script->get_base_script();
while (base.is_valid()) {
if (p_instance) {
members[base.ptr()] = Set<StringName>();
members[base.ptr()] = RBSet<StringName>();
base->get_members(&(members[base.ptr()]));
}
constants[base.ptr()] = Map<StringName, Variant>();
constants[base.ptr()] = HashMap<StringName, Variant>();
base->get_constants(&(constants[base.ptr()]));
base = base->get_base_script();
}
// Members
for (ScriptMemberMap::Element *sm = members.front(); sm; sm = sm->next()) {
for (Set<StringName>::Element *E = sm->get().front(); E; E = E->next()) {
for (KeyValue<const Script *, RBSet<StringName>> sm : members) {
for (RBSet<StringName>::Element *E = sm.value.front(); E; E = E->next()) {
Variant m;
if (p_instance->get(E->get(), m)) {
String script_path = sm->key() == p_script ? "" : sm->key()->get_path().get_file() + "/";
String script_path = sm.key == p_script ? "" : sm.key->get_path().get_file() + "/";
PropertyInfo pi(m.get_type(), "Members/" + script_path + E->get());
properties.push_back(SceneDebuggerProperty(pi, m));
}
}
}
// Constants
for (ScriptConstantsMap::Element *sc = constants.front(); sc; sc = sc->next()) {
for (const KeyValue<StringName, Variant> &E : sc->get()) {
String script_path = sc->key() == p_script ? "" : sc->key()->get_path().get_file() + "/";
for (KeyValue<const Script *, HashMap<StringName, Variant>> &sc : constants) {
for (const KeyValue<StringName, Variant> &E : sc.value) {
String script_path = sc.key == p_script ? "" : sc.key->get_path().get_file() + "/";
if (E.value.get_type() == Variant::OBJECT) {
Variant id = ((Object *)E.value)->get_instance_id();
PropertyInfo pi(id.get_type(), "Constants/" + E.key, PROPERTY_HINT_OBJECT_ID, "Object");
@@ -624,12 +624,12 @@ void LiveEditor::_node_set_func(int p_id, const StringName &p_prop, const Varian
base = scene_tree->root->get_node(live_edit_root);
}
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
HashMap<String, RBSet<Node *>>::Iterator E = live_scene_edit_cache.find(live_edit_scene);
if (!E) {
return; //scene not editable
}
for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) {
for (RBSet<Node *>::Element *F = E->value.front(); F; F = F->next()) {
Node *n = F->get();
if (base && !base->is_ancestor_of(n)) {
@@ -668,12 +668,12 @@ void LiveEditor::_node_call_func(int p_id, const StringName &p_method, const Var
base = scene_tree->root->get_node(live_edit_root);
}
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
HashMap<String, RBSet<Node *>>::Iterator E = live_scene_edit_cache.find(live_edit_scene);
if (!E) {
return; //scene not editable
}
for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) {
for (RBSet<Node *>::Element *F = E->value.front(); F; F = F->next()) {
Node *n = F->get();
if (base && !base->is_ancestor_of(n)) {
@@ -753,12 +753,12 @@ void LiveEditor::_create_node_func(const NodePath &p_parent, const String &p_typ
base = scene_tree->root->get_node(live_edit_root);
}
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
HashMap<String, RBSet<Node *>>::Iterator E = live_scene_edit_cache.find(live_edit_scene);
if (!E) {
return; //scene not editable
}
for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) {
for (RBSet<Node *>::Element *F = E->value.front(); F; F = F->next()) {
Node *n = F->get();
if (base && !base->is_ancestor_of(n)) {
@@ -797,12 +797,12 @@ void LiveEditor::_instance_node_func(const NodePath &p_parent, const String &p_p
base = scene_tree->root->get_node(live_edit_root);
}
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
HashMap<String, RBSet<Node *>>::Iterator E = live_scene_edit_cache.find(live_edit_scene);
if (!E) {
return; //scene not editable
}
for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) {
for (RBSet<Node *>::Element *F = E->value.front(); F; F = F->next()) {
Node *n = F->get();
if (base && !base->is_ancestor_of(n)) {
@@ -835,13 +835,13 @@ void LiveEditor::_remove_node_func(const NodePath &p_at) {
base = scene_tree->root->get_node(live_edit_root);
}
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
HashMap<String, RBSet<Node *>>::Iterator E = live_scene_edit_cache.find(live_edit_scene);
if (!E) {
return; //scene not editable
}
for (Set<Node *>::Element *F = E->get().front(); F;) {
Set<Node *>::Element *N = F->next();
for (RBSet<Node *>::Element *F = E->value.front(); F;) {
RBSet<Node *>::Element *N = F->next();
Node *n = F->get();
@@ -871,13 +871,13 @@ void LiveEditor::_remove_and_keep_node_func(const NodePath &p_at, ObjectID p_kee
base = scene_tree->root->get_node(live_edit_root);
}
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
HashMap<String, RBSet<Node *>>::Iterator E = live_scene_edit_cache.find(live_edit_scene);
if (!E) {
return; //scene not editable
}
for (Set<Node *>::Element *F = E->get().front(); F;) {
Set<Node *>::Element *N = F->next();
for (RBSet<Node *>::Element *F = E->value.front(); F;) {
RBSet<Node *>::Element *N = F->next();
Node *n = F->get();
@@ -910,13 +910,13 @@ void LiveEditor::_restore_node_func(ObjectID p_id, const NodePath &p_at, int p_a
base = scene_tree->root->get_node(live_edit_root);
}
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
HashMap<String, RBSet<Node *>>::Iterator E = live_scene_edit_cache.find(live_edit_scene);
if (!E) {
return; //scene not editable
}
for (Set<Node *>::Element *F = E->get().front(); F;) {
Set<Node *>::Element *N = F->next();
for (RBSet<Node *>::Element *F = E->value.front(); F;) {
RBSet<Node *>::Element *N = F->next();
Node *n = F->get();
@@ -929,23 +929,23 @@ void LiveEditor::_restore_node_func(ObjectID p_id, const NodePath &p_at, int p_a
}
Node *n2 = n->get_node(p_at);
Map<Node *, Map<ObjectID, Node *>>::Element *EN = live_edit_remove_list.find(n);
HashMap<Node *, HashMap<ObjectID, Node *>>::Iterator EN = live_edit_remove_list.find(n);
if (!EN) {
continue;
}
Map<ObjectID, Node *>::Element *FN = EN->get().find(p_id);
HashMap<ObjectID, Node *>::Iterator FN = EN->value.find(p_id);
if (!FN) {
continue;
}
n2->add_child(FN->get());
n2->add_child(FN->value);
EN->get().erase(FN);
EN->value.remove(FN);
if (EN->get().size() == 0) {
live_edit_remove_list.erase(EN);
if (EN->value.size() == 0) {
live_edit_remove_list.remove(EN);
}
F = N;
@@ -963,12 +963,12 @@ void LiveEditor::_duplicate_node_func(const NodePath &p_at, const String &p_new_
base = scene_tree->root->get_node(live_edit_root);
}
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
HashMap<String, RBSet<Node *>>::Iterator E = live_scene_edit_cache.find(live_edit_scene);
if (!E) {
return; //scene not editable
}
for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) {
for (RBSet<Node *>::Element *F = E->value.front(); F; F = F->next()) {
Node *n = F->get();
if (base && !base->is_ancestor_of(n)) {
@@ -1002,12 +1002,12 @@ void LiveEditor::_reparent_node_func(const NodePath &p_at, const NodePath &p_new
base = scene_tree->root->get_node(live_edit_root);
}
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
HashMap<String, RBSet<Node *>>::Iterator E = live_scene_edit_cache.find(live_edit_scene);
if (!E) {
return; //scene not editable
}
for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) {
for (RBSet<Node *>::Element *F = E->value.front(); F; F = F->next()) {
Node *n = F->get();
if (base && !base->is_ancestor_of(n)) {