summaryrefslogtreecommitdiffstats
path: root/editor/scene_tree_dock.cpp
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 /editor/scene_tree_dock.cpp
parent396def9b66c476f7834604adb7136ca903ed01be (diff)
downloadredot-engine-746dddc0673d7261f19b1e056e90e6e3a49ef33a.tar.gz
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 'editor/scene_tree_dock.cpp')
-rw-r--r--editor/scene_tree_dock.cpp76
1 files changed, 38 insertions, 38 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index b385460232..afb3ac7c15 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -460,7 +460,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
selection.sort_custom<Node::Comparator>();
for (Node *node : selection) {
- Map<const Node *, Node *> duplimap;
+ HashMap<const Node *, Node *> duplimap;
Node *dup = node->duplicate_from_editor(duplimap);
ERR_CONTINUE(!dup);
@@ -658,7 +658,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
List<Node *> owned;
node->get_owned_by(node->get_owner(), &owned);
- Map<const Node *, Node *> duplimap;
+ HashMap<const Node *, Node *> duplimap;
Node *dup = node->duplicate_from_editor(duplimap);
ERR_CONTINUE(!dup);
@@ -717,7 +717,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
List<Node *> nodes = editor_selection->get_selected_node_list();
- Set<Node *> nodeset;
+ RBSet<Node *> nodeset;
for (Node *E : nodes) {
nodeset.insert(E);
}
@@ -1402,7 +1402,7 @@ void SceneTreeDock::_set_owners(Node *p_owner, const Array &p_nodes) {
}
}
-void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, Map<Node *, NodePath> *p_renames) {
+void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, HashMap<Node *, NodePath> *p_renames) {
base_path.push_back(p_node->get_name());
if (new_base_path.size()) {
new_base_path.push_back(p_node->get_name());
@@ -1420,7 +1420,7 @@ void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<Stri
}
}
-void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, Map<Node *, NodePath> *p_renames) {
+void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, HashMap<Node *, NodePath> *p_renames) {
Vector<StringName> base_path;
Node *n = p_node->get_parent();
while (n) {
@@ -1443,24 +1443,24 @@ void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, Map<Node
_fill_path_renames(base_path, new_base_path, p_node, p_renames);
}
-bool SceneTreeDock::_update_node_path(Node *p_root_node, NodePath &r_node_path, Map<Node *, NodePath> *p_renames) const {
+bool SceneTreeDock::_update_node_path(Node *p_root_node, NodePath &r_node_path, HashMap<Node *, NodePath> *p_renames) const {
Node *target_node = p_root_node->get_node_or_null(r_node_path);
ERR_FAIL_NULL_V_MSG(target_node, false, "Found invalid node path '" + String(r_node_path) + "' on node '" + String(scene_root->get_path_to(p_root_node)) + "'");
// Try to find the target node in modified node paths.
- Map<Node *, NodePath>::Element *found_node_path = p_renames->find(target_node);
+ HashMap<Node *, NodePath>::Iterator found_node_path = p_renames->find(target_node);
if (found_node_path) {
- Map<Node *, NodePath>::Element *found_root_path = p_renames->find(p_root_node);
- NodePath root_path_new = found_root_path ? found_root_path->get() : p_root_node->get_path();
- r_node_path = root_path_new.rel_path_to(found_node_path->get());
+ HashMap<Node *, NodePath>::Iterator found_root_path = p_renames->find(p_root_node);
+ NodePath root_path_new = found_root_path ? found_root_path->value : p_root_node->get_path();
+ r_node_path = root_path_new.rel_path_to(found_node_path->value);
return true;
}
// Update the path if the base node has changed and has not been deleted.
- Map<Node *, NodePath>::Element *found_root_path = p_renames->find(p_root_node);
+ HashMap<Node *, NodePath>::Iterator found_root_path = p_renames->find(p_root_node);
if (found_root_path) {
- NodePath root_path_new = found_root_path->get();
+ NodePath root_path_new = found_root_path->value;
if (!root_path_new.is_empty()) {
NodePath old_abs_path = NodePath(String(p_root_node->get_path()).plus_file(r_node_path));
old_abs_path.simplify();
@@ -1473,7 +1473,7 @@ bool SceneTreeDock::_update_node_path(Node *p_root_node, NodePath &r_node_path,
return false;
}
-bool SceneTreeDock::_check_node_path_recursive(Node *p_root_node, Variant &r_variant, Map<Node *, NodePath> *p_renames) const {
+bool SceneTreeDock::_check_node_path_recursive(Node *p_root_node, Variant &r_variant, HashMap<Node *, NodePath> *p_renames) const {
switch (r_variant.get_type()) {
case Variant::NODE_PATH: {
NodePath node_path = r_variant;
@@ -1528,8 +1528,8 @@ bool SceneTreeDock::_check_node_path_recursive(Node *p_root_node, Variant &r_var
return false;
}
-void SceneTreeDock::perform_node_renames(Node *p_base, Map<Node *, NodePath> *p_renames, Map<Ref<Animation>, Set<int>> *r_rem_anims) {
- Map<Ref<Animation>, Set<int>> rem_anims;
+void SceneTreeDock::perform_node_renames(Node *p_base, HashMap<Node *, NodePath> *p_renames, HashMap<Ref<Animation>, RBSet<int>> *r_rem_anims) {
+ HashMap<Ref<Animation>, RBSet<int>> rem_anims;
if (!r_rem_anims) {
r_rem_anims = &rem_anims;
}
@@ -1543,8 +1543,8 @@ void SceneTreeDock::perform_node_renames(Node *p_base, Map<Node *, NodePath> *p_
}
// No renaming if base node is deleted.
- Map<Node *, NodePath>::Element *found_base_path = p_renames->find(p_base);
- if (found_base_path && found_base_path->get().is_empty()) {
+ HashMap<Node *, NodePath>::Iterator found_base_path = p_renames->find(p_base);
+ if (found_base_path && found_base_path->value.is_empty()) {
return;
}
@@ -1575,20 +1575,20 @@ void SceneTreeDock::perform_node_renames(Node *p_base, Map<Node *, NodePath> *p_
Node *root = ap->get_node(ap->get_root());
if (root) {
- Map<Node *, NodePath>::Element *found_root_path = p_renames->find(root);
- NodePath new_root_path = found_root_path ? found_root_path->get() : root->get_path();
+ HashMap<Node *, NodePath>::Iterator found_root_path = p_renames->find(root);
+ NodePath new_root_path = found_root_path ? found_root_path->value : root->get_path();
if (!new_root_path.is_empty()) { // No renaming if root node is deleted.
for (const StringName &E : anims) {
Ref<Animation> anim = ap->get_animation(E);
if (!r_rem_anims->has(anim)) {
- r_rem_anims->insert(anim, Set<int>());
- Set<int> &ran = r_rem_anims->find(anim)->get();
+ r_rem_anims->insert(anim, RBSet<int>());
+ RBSet<int> &ran = r_rem_anims->find(anim)->value;
for (int i = 0; i < anim->get_track_count(); i++) {
ran.insert(i);
}
}
- Set<int> &ran = r_rem_anims->find(anim)->get();
+ RBSet<int> &ran = r_rem_anims->find(anim)->value;
if (anim.is_null()) {
continue;
@@ -1605,13 +1605,13 @@ void SceneTreeDock::perform_node_renames(Node *p_base, Map<Node *, NodePath> *p_
continue; //channel was removed
}
- Map<Node *, NodePath>::Element *found_path = p_renames->find(n);
+ HashMap<Node *, NodePath>::Iterator found_path = p_renames->find(n);
if (found_path) {
- if (found_path->get() == NodePath()) {
+ if (found_path->value == NodePath()) {
//will be erased
int idx = 0;
- Set<int>::Element *EI = ran.front();
+ RBSet<int>::Element *EI = ran.front();
ERR_FAIL_COND(!EI); //bug
while (EI->get() != i) {
idx++;
@@ -1631,7 +1631,7 @@ void SceneTreeDock::perform_node_renames(Node *p_base, Map<Node *, NodePath> *p_
} else {
//will be renamed
- NodePath rel_path = new_root_path.rel_path_to(found_path->get());
+ NodePath rel_path = new_root_path.rel_path_to(found_path->value);
NodePath new_path = NodePath(rel_path.get_names(), track_np.get_subnames(), false);
if (new_path == track_np) {
@@ -1653,7 +1653,7 @@ void SceneTreeDock::perform_node_renames(Node *p_base, Map<Node *, NodePath> *p_
}
void SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name) {
- Map<Node *, NodePath> path_renames;
+ HashMap<Node *, NodePath> path_renames;
Vector<StringName> base_path;
Node *n = p_node->get_parent();
@@ -1774,7 +1774,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
editor_data->get_undo_redo().create_action(TTR("Reparent Node"));
- Map<Node *, NodePath> path_renames;
+ HashMap<Node *, NodePath> path_renames;
Vector<StringName> former_names;
int inc = 0;
@@ -1811,9 +1811,9 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
// Name was modified, fix the path renames.
if (old_name.casecmp_to(new_name) != 0) {
// Fix the to name to have the new name.
- Map<Node *, NodePath>::Element *found_path = path_renames.find(node);
+ HashMap<Node *, NodePath>::Iterator found_path = path_renames.find(node);
if (found_path) {
- NodePath old_new_name = found_path->get();
+ NodePath old_new_name = found_path->value;
Vector<StringName> unfixed_new_names = old_new_name.get_names();
Vector<StringName> fixed_new_names;
@@ -2058,7 +2058,7 @@ void SceneTreeDock::_delete_confirm(bool p_cut) {
} else {
remove_list.sort_custom<Node::Comparator>(); //sort nodes to keep positions
- Map<Node *, NodePath> path_renames;
+ HashMap<Node *, NodePath> path_renames;
//delete from animation
for (Node *n : remove_list) {
@@ -2148,7 +2148,7 @@ void SceneTreeDock::_selection_changed() {
//automatically turn on multi-edit
_tool_selected(TOOL_MULTI_EDIT);
} else if (selection_size == 1) {
- _push_item(editor_selection->get_selection().front()->key());
+ _push_item(editor_selection->get_selection().begin()->key);
} else if (selection_size == 0) {
_push_item(nullptr);
}
@@ -2407,7 +2407,7 @@ void SceneTreeDock::_new_scene_from(String p_file) {
Node *base = selection.front()->get();
- Map<const Node *, Node *> duplimap;
+ HashMap<const Node *, Node *> duplimap;
Node *copy = base->duplicate_from_editor(duplimap);
if (copy) {
@@ -3038,14 +3038,14 @@ List<Node *> SceneTreeDock::paste_nodes() {
ur.create_action(TTR("Paste Node(s)"));
ur.add_do_method(editor_selection, "clear");
- Map<Ref<Resource>, Ref<Resource>> resource_remap;
+ HashMap<Ref<Resource>, Ref<Resource>> resource_remap;
String target_scene;
if (edited_scene) {
target_scene = edited_scene->get_scene_file_path();
}
if (target_scene != clipboard_source_scene) {
if (!clipboard_resource_remap.has(target_scene)) {
- Map<Ref<Resource>, Ref<Resource>> remap;
+ HashMap<Ref<Resource>, Ref<Resource>> remap;
for (Node *E : node_clipboard) {
_create_remap_for_node(E, remap);
}
@@ -3055,7 +3055,7 @@ List<Node *> SceneTreeDock::paste_nodes() {
}
for (Node *node : node_clipboard) {
- Map<const Node *, Node *> duplimap;
+ HashMap<const Node *, Node *> duplimap;
Node *dup = node->duplicate_from_editor(duplimap, resource_remap);
ERR_CONTINUE(!dup);
@@ -3241,7 +3241,7 @@ void SceneTreeDock::_clear_clipboard() {
clipboard_resource_remap.clear();
}
-void SceneTreeDock::_create_remap_for_node(Node *p_node, Map<Ref<Resource>, Ref<Resource>> &r_remap) {
+void SceneTreeDock::_create_remap_for_node(Node *p_node, HashMap<Ref<Resource>, Ref<Resource>> &r_remap) {
List<PropertyInfo> props;
p_node->get_property_list(&props);
@@ -3280,7 +3280,7 @@ void SceneTreeDock::_create_remap_for_node(Node *p_node, Map<Ref<Resource>, Ref<
}
}
-void SceneTreeDock::_create_remap_for_resource(Ref<Resource> p_resource, Map<Ref<Resource>, Ref<Resource>> &r_remap) {
+void SceneTreeDock::_create_remap_for_resource(Ref<Resource> p_resource, HashMap<Ref<Resource>, Ref<Resource>> &r_remap) {
r_remap[p_resource] = p_resource->duplicate();
List<PropertyInfo> props;