@@ -183,7 +183,7 @@ void Node::_propagate_ready() {
183
183
data.ready_notified = true ;
184
184
data.blocked ++;
185
185
for (int i = 0 ; i < data.children .size (); i++) {
186
- data.children [i] ->_propagate_ready ();
186
+ data.children . get_unchecked (i) ->_propagate_ready ();
187
187
}
188
188
data.blocked --;
189
189
@@ -235,7 +235,7 @@ void Node::_propagate_physics_interpolation_reset_requested(bool p_requested) {
235
235
236
236
data.blocked ++;
237
237
for (int i = 0 ; i < data.children .size (); i++) {
238
- data.children [i] ->_propagate_physics_interpolation_reset_requested (p_requested);
238
+ data.children . get_unchecked (i) ->_propagate_physics_interpolation_reset_requested (p_requested);
239
239
}
240
240
data.blocked --;
241
241
}
@@ -281,8 +281,9 @@ void Node::_propagate_enter_tree() {
281
281
// block while adding children
282
282
283
283
for (int i = 0 ; i < data.children .size (); i++) {
284
- if (!data.children [i]->is_inside_tree ()) { // could have been added in enter_tree
285
- data.children [i]->_propagate_enter_tree ();
284
+ Node *child = data.children .get_unchecked (i);
285
+ if (!child->is_inside_tree ()) { // could have been added in enter_tree
286
+ child->_propagate_enter_tree ();
286
287
}
287
288
}
288
289
@@ -429,7 +430,7 @@ void Node::move_child(Node *p_child, int p_pos) {
429
430
data.blocked ++;
430
431
// new pos first
431
432
for (int i = motion_from; i <= motion_to; i++) {
432
- data.children [i] ->data .pos = i;
433
+ data.children . get_unchecked (i) ->data .pos = i;
433
434
}
434
435
// notification second
435
436
move_child_notify (p_child);
@@ -456,7 +457,7 @@ void Node::_propagate_groups_dirty() {
456
457
}
457
458
458
459
for (int i = 0 ; i < data.children .size (); i++) {
459
- data.children [i] ->_propagate_groups_dirty ();
460
+ data.children . get_unchecked (i) ->_propagate_groups_dirty ();
460
461
}
461
462
}
462
463
@@ -563,9 +564,11 @@ void Node::_propagate_pause_owner(Node *p_owner) {
563
564
void Node::_propagate_pause_change_notification (int p_notification) {
564
565
notification (p_notification);
565
566
567
+ Node **children = data.children .ptr ();
568
+
566
569
for (int i = 0 ; i < data.children .size (); i++) {
567
- if (data. children [i]->data .pause_mode == PAUSE_MODE_INHERIT) {
568
- data. children [i]->_propagate_pause_change_notification (p_notification);
570
+ if (children[i]->data .pause_mode == PAUSE_MODE_INHERIT) {
571
+ children[i]->_propagate_pause_change_notification (p_notification);
569
572
}
570
573
}
571
574
}
@@ -575,7 +578,7 @@ void Node::set_network_master(int p_peer_id, bool p_recursive) {
575
578
576
579
if (p_recursive) {
577
580
for (int i = 0 ; i < data.children .size (); i++) {
578
- data.children [i] ->set_network_master (p_peer_id, true );
581
+ data.children . get_unchecked (i) ->set_network_master (p_peer_id, true );
579
582
}
580
583
}
581
584
}
@@ -1400,7 +1403,8 @@ int Node::get_child_count() const {
1400
1403
Node *Node::get_child (int p_index) const {
1401
1404
ERR_FAIL_INDEX_V (p_index, data.children .size (), nullptr );
1402
1405
1403
- return data.children [p_index];
1406
+ // Index already checked above, can use unsafe version here.
1407
+ return data.children .get_unchecked (p_index);
1404
1408
}
1405
1409
1406
1410
Node *Node::_get_child_by_name (const StringName &p_name) const {
@@ -1468,7 +1472,7 @@ Node *Node::get_node_or_null(const NodePath &p_path) const {
1468
1472
next = nullptr ;
1469
1473
1470
1474
for (int j = 0 ; j < current->data .children .size (); j++) {
1471
- Node *child = current->data .children [j] ;
1475
+ Node *child = current->data .children . get_unchecked (j) ;
1472
1476
1473
1477
if (child->data .name == name) {
1474
1478
next = child;
@@ -1936,7 +1940,7 @@ void Node::_print_tree(const Node *p_node) {
1936
1940
void Node::_propagate_reverse_notification (int p_notification) {
1937
1941
data.blocked ++;
1938
1942
for (int i = data.children .size () - 1 ; i >= 0 ; i--) {
1939
- data.children [i] ->_propagate_reverse_notification (p_notification);
1943
+ data.children . get_unchecked (i) ->_propagate_reverse_notification (p_notification);
1940
1944
}
1941
1945
1942
1946
notification (p_notification, true );
@@ -1953,7 +1957,7 @@ void Node::_propagate_deferred_notification(int p_notification, bool p_reverse)
1953
1957
}
1954
1958
1955
1959
for (int i = 0 ; i < data.children .size (); i++) {
1956
- data.children [i] ->_propagate_deferred_notification (p_notification, p_reverse);
1960
+ data.children . get_unchecked (i) ->_propagate_deferred_notification (p_notification, p_reverse);
1957
1961
}
1958
1962
1959
1963
if (p_reverse) {
@@ -1968,7 +1972,7 @@ void Node::propagate_notification(int p_notification) {
1968
1972
notification (p_notification);
1969
1973
1970
1974
for (int i = 0 ; i < data.children .size (); i++) {
1971
- data.children [i] ->propagate_notification (p_notification);
1975
+ data.children . get_unchecked (i) ->propagate_notification (p_notification);
1972
1976
}
1973
1977
data.blocked --;
1974
1978
}
@@ -1981,7 +1985,7 @@ void Node::propagate_call(const StringName &p_method, const Array &p_args, const
1981
1985
}
1982
1986
1983
1987
for (int i = 0 ; i < data.children .size (); i++) {
1984
- data.children [i] ->propagate_call (p_method, p_args, p_parent_first);
1988
+ data.children . get_unchecked (i) ->propagate_call (p_method, p_args, p_parent_first);
1985
1989
}
1986
1990
1987
1991
if (!p_parent_first && has_method (p_method)) {
@@ -1998,7 +2002,7 @@ void Node::_propagate_replace_owner(Node *p_owner, Node *p_by_owner) {
1998
2002
1999
2003
data.blocked ++;
2000
2004
for (int i = 0 ; i < data.children .size (); i++) {
2001
- data.children [i] ->_propagate_replace_owner (p_owner, p_by_owner);
2005
+ data.children . get_unchecked (i) ->_propagate_replace_owner (p_owner, p_by_owner);
2002
2006
}
2003
2007
data.blocked --;
2004
2008
}
0 commit comments