diff options
author | Juan Linietsky <reduzio@gmail.com> | 2018-11-18 11:47:19 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2018-11-18 11:48:21 -0300 |
commit | 2d6b994e476f00e5725117501f6fc006eadd0d30 (patch) | |
tree | 922259f0c28f2a5d1b44e85e871a638bcac83123 /scene/main | |
parent | 4a050568a28898a45cebe350f31bb2af867b32ff (diff) |
Massive speed up on deleting nodes, fixes #18673
Also makes the editor exit faster
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/node.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 3242068bf7..ae2ab2af80 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -157,7 +157,7 @@ void Node::_notification(int p_notification) { // kill children as cleanly as possible while (data.children.size()) { - Node *child = data.children[0]; + Node *child = data.children[data.children.size() - 1]; //begin from the end because its faster and more consistent with creation remove_child(child); memdelete(child); } @@ -1182,13 +1182,24 @@ void Node::remove_child(Node *p_child) { ERR_FAIL_COND(data.blocked > 0); } + int child_count = data.children.size(); + Node **children = data.children.ptrw(); int idx = -1; - for (int i = 0; i < data.children.size(); i++) { - if (data.children[i] == p_child) { + if (p_child->data.pos >= 0 && p_child->data.pos < child_count) { + if (children[p_child->data.pos] == p_child) { + idx = p_child->data.pos; + } + } + + if (idx == -1) { //maybe removed while unparenting or something and index was not updated, so just in case the above fails, try this. + for (int i = 0; i < child_count; i++) { - idx = i; - break; + if (children[i] == p_child) { + + idx = i; + break; + } } } @@ -1205,10 +1216,14 @@ void Node::remove_child(Node *p_child) { data.children.remove(idx); - for (int i = idx; i < data.children.size(); i++) { + //update pointer and size + child_count = data.children.size(); + children = data.children.ptrw(); - data.children[i]->data.pos = i; - data.children[i]->notification(NOTIFICATION_MOVED_IN_PARENT); + for (int i = idx; i < child_count; i++) { + + children[i]->data.pos = i; + children[i]->notification(NOTIFICATION_MOVED_IN_PARENT); } p_child->data.parent = NULL; |