Skip to content

Commit 195c4a3

Browse files
committed
Convert while-pop_front loop to iterator loop.
1 parent 6392241 commit 195c4a3

14 files changed

+74
-91
lines changed

core/debugger/debugger_marshalls.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool DebuggerMarshalls::ScriptStackVariable::deserialize(const Array &p_arr) {
9494
return true;
9595
}
9696

97-
Array DebuggerMarshalls::OutputError::serialize() {
97+
Array DebuggerMarshalls::OutputError::serialize() const {
9898
unsigned int size = callstack.size();
9999
Array arr = {
100100
hr,

core/debugger/debugger_marshalls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct DebuggerMarshalls {
6565
bool warning = false;
6666
Vector<ScriptLanguage::StackInfo> callstack;
6767

68-
Array serialize();
68+
Array serialize() const;
6969
bool deserialize(const Array &p_arr);
7070
};
7171

core/debugger/remote_debugger.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,10 @@ void RemoteDebugger::flush_output() {
237237
output_strings.clear();
238238
}
239239

240-
while (errors.size()) {
241-
ErrorMessage oe = errors.front()->get();
240+
for (const ErrorMessage &oe : errors) {
242241
_put_msg("error", oe.serialize());
243-
errors.pop_front();
244242
}
243+
errors.clear();
245244

246245
// Update limits
247246
uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000;

core/debugger/remote_debugger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class RemoteDebugger : public EngineDebugger {
6060
MessageType type;
6161
};
6262
List<OutputString> output_strings;
63-
List<ErrorMessage> errors;
63+
LocalVector<ErrorMessage> errors;
6464

6565
int n_messages_dropped = 0;
6666
int max_errors_per_second = 0;

core/math/quick_hull.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
236236
Vector3 v = p_points[f.points_over[next]];
237237

238238
//find lit faces and lit edges
239-
List<List<Face>::Element *> lit_faces; //lit face is a death sentence
239+
LocalVector<List<Face>::Element *> lit_faces; //lit face is a death sentence
240240

241241
HashMap<Edge, FaceConnect, Edge> lit_edges; //create this on the flight, should not be that bad for performance and simplifies code a lot
242242

@@ -314,10 +314,10 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
314314

315315
//erase lit faces
316316

317-
while (lit_faces.size()) {
318-
faces.erase(lit_faces.front()->get());
319-
lit_faces.pop_front();
317+
for (List<Face>::Element *lf : lit_faces) {
318+
faces.erase(lf);
320319
}
320+
lit_faces.clear();
321321

322322
//put faces that contain no points on the front
323323

core/object/script_language.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
779779
}
780780

781781
properties = p_properties;
782-
List<StringName> to_remove;
782+
LocalVector<StringName> to_remove;
783783

784784
for (KeyValue<StringName, Variant> &E : values) {
785785
if (!new_values.has(E.key)) {
@@ -795,10 +795,10 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
795795
}
796796
}
797797

798-
while (to_remove.size()) {
799-
values.erase(to_remove.front()->get());
800-
to_remove.pop_front();
798+
for (const StringName &key : to_remove) {
799+
values.erase(key);
801800
}
801+
to_remove.clear();
802802

803803
if (owner && owner->get_script_instance() == this) {
804804
owner->notify_property_list_changed();

editor/doc_tools.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ Error DocTools::erase_classes(const String &p_dir) {
12611261
return err;
12621262
}
12631263

1264-
List<String> to_erase;
1264+
LocalVector<String> to_erase;
12651265

12661266
da->list_dir_begin();
12671267
String path;
@@ -1274,9 +1274,8 @@ Error DocTools::erase_classes(const String &p_dir) {
12741274
}
12751275
da->list_dir_end();
12761276

1277-
while (to_erase.size()) {
1278-
da->remove(to_erase.front()->get());
1279-
to_erase.pop_front();
1277+
for (const String &file : to_erase) {
1278+
da->remove(file);
12801279
}
12811280

12821281
return OK;

editor/plugins/asset_library_editor_plugin.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ void EditorAssetLibrary::_update_image_queue() {
948948
const int max_images = 6;
949949
int current_images = 0;
950950

951-
List<int> to_delete;
951+
LocalVector<int> to_delete;
952952
for (KeyValue<int, ImageQueue> &E : image_queue) {
953953
if (!E.value.active && current_images < max_images) {
954954
String cache_filename_base = EditorPaths::get_singleton()->get_cache_dir().path_join("assetimage_" + E.value.image_url.md5_text());
@@ -973,10 +973,9 @@ void EditorAssetLibrary::_update_image_queue() {
973973
}
974974
}
975975

976-
while (to_delete.size()) {
977-
image_queue[to_delete.front()->get()].request->queue_free();
978-
image_queue.erase(to_delete.front()->get());
979-
to_delete.pop_front();
976+
for (const int key : to_delete) {
977+
image_queue[key].request->queue_free();
978+
image_queue.erase(key);
980979
}
981980
}
982981

scene/animation/animation_mixer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
#include "core/config/engine.h"
3535
#include "core/config/project_settings.h"
36-
#include "core/string/string_name.h"
3736
#include "scene/2d/audio_stream_player_2d.h"
3837
#include "scene/animation/animation_player.h"
3938
#include "scene/audio/audio_stream_player.h"
@@ -168,7 +167,7 @@ void AnimationMixer::_animation_set_cache_update() {
168167
}
169168

170169
// Check removed.
171-
List<StringName> to_erase;
170+
LocalVector<StringName> to_erase;
172171
for (const KeyValue<StringName, AnimationData> &E : animation_set) {
173172
if (E.value.last_update != animation_set_update_pass) {
174173
// Was not updated, must be erased.
@@ -177,10 +176,10 @@ void AnimationMixer::_animation_set_cache_update() {
177176
}
178177
}
179178

180-
while (to_erase.size()) {
181-
animation_set.erase(to_erase.front()->get());
182-
to_erase.pop_front();
179+
for (const StringName &key : to_erase) {
180+
animation_set.erase(key);
183181
}
182+
to_erase.clear();
184183

185184
if (clear_cache_needed) {
186185
// If something was modified or removed, caches need to be cleared.

scene/animation/animation_player.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -895,25 +895,24 @@ void AnimationPlayer::_animation_removed(const StringName &p_name, const StringN
895895
_animation_set_cache_update();
896896

897897
// Erase blends if needed
898-
List<BlendKey> to_erase;
898+
LocalVector<BlendKey> to_erase;
899899
for (const KeyValue<BlendKey, double> &E : blend_times) {
900900
BlendKey bk = E.key;
901901
if (bk.from == name || bk.to == name) {
902902
to_erase.push_back(bk);
903903
}
904904
}
905905

906-
while (to_erase.size()) {
907-
blend_times.erase(to_erase.front()->get());
908-
to_erase.pop_front();
906+
for (const BlendKey &bk : to_erase) {
907+
blend_times.erase(bk);
909908
}
910909
}
911910

912911
void AnimationPlayer::_rename_animation(const StringName &p_from_name, const StringName &p_to_name) {
913912
AnimationMixer::_rename_animation(p_from_name, p_to_name);
914913

915914
// Rename autoplay or blends if needed.
916-
List<BlendKey> to_erase;
915+
LocalVector<BlendKey> to_erase;
917916
HashMap<BlendKey, double, BlendKey> to_insert;
918917
for (const KeyValue<BlendKey, double> &E : blend_times) {
919918
BlendKey bk = E.key;
@@ -934,10 +933,10 @@ void AnimationPlayer::_rename_animation(const StringName &p_from_name, const Str
934933
}
935934
}
936935

937-
while (to_erase.size()) {
938-
blend_times.erase(to_erase.front()->get());
939-
to_erase.pop_front();
936+
for (const BlendKey &bk : to_erase) {
937+
blend_times.erase(bk);
940938
}
939+
to_erase.clear();
941940

942941
while (to_insert.size()) {
943942
blend_times[to_insert.begin()->key] = to_insert.begin()->value;

scene/main/viewport.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4074,8 +4074,8 @@ void Viewport::_camera_2d_set(Camera2D *p_camera_2d) {
40744074

40754075
#ifndef PHYSICS_2D_DISABLED
40764076
void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paused_only, uint64_t p_frame_reference) {
4077-
List<ObjectID> to_erase;
4078-
List<ObjectID> to_mouse_exit;
4077+
LocalVector<ObjectID> to_erase;
4078+
LocalVector<ObjectID> to_mouse_exit;
40794079

40804080
for (const KeyValue<ObjectID, uint64_t> &E : physics_2d_mouseover) {
40814081
if (!p_clean_all_frames && E.value == p_frame_reference) {
@@ -4095,14 +4095,14 @@ void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paus
40954095
to_erase.push_back(E.key);
40964096
}
40974097

4098-
while (to_erase.size()) {
4099-
physics_2d_mouseover.erase(to_erase.front()->get());
4100-
to_erase.pop_front();
4098+
for (const ObjectID &key : to_erase) {
4099+
physics_2d_mouseover.erase(key);
41014100
}
4101+
to_erase.clear();
41024102

41034103
// Per-shape.
4104-
List<Pair<ObjectID, int>> shapes_to_erase;
4105-
List<Pair<ObjectID, int>> shapes_to_mouse_exit;
4104+
LocalVector<Pair<ObjectID, int>> shapes_to_erase;
4105+
LocalVector<Pair<ObjectID, int>> shapes_to_mouse_exit;
41064106

41074107
for (KeyValue<Pair<ObjectID, int>, uint64_t> &E : physics_2d_shape_mouseover) {
41084108
if (!p_clean_all_frames && E.value == p_frame_reference) {
@@ -4122,24 +4122,20 @@ void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paus
41224122
shapes_to_erase.push_back(E.key);
41234123
}
41244124

4125-
while (shapes_to_erase.size()) {
4126-
physics_2d_shape_mouseover.erase(shapes_to_erase.front()->get());
4127-
shapes_to_erase.pop_front();
4125+
for (const Pair<ObjectID, int> &key : shapes_to_erase) {
4126+
physics_2d_shape_mouseover.erase(key);
41284127
}
41294128

4130-
while (to_mouse_exit.size()) {
4131-
Object *o = ObjectDB::get_instance(to_mouse_exit.front()->get());
4129+
for (const ObjectID &key : to_mouse_exit) {
4130+
Object *o = ObjectDB::get_instance(key);
41324131
CollisionObject2D *co = Object::cast_to<CollisionObject2D>(o);
41334132
co->_mouse_exit();
4134-
to_mouse_exit.pop_front();
41354133
}
41364134

4137-
while (shapes_to_mouse_exit.size()) {
4138-
Pair<ObjectID, int> e = shapes_to_mouse_exit.front()->get();
4139-
Object *o = ObjectDB::get_instance(e.first);
4135+
for (const Pair<ObjectID, int> &key : shapes_to_mouse_exit) {
4136+
Object *o = ObjectDB::get_instance(key.first);
41404137
CollisionObject2D *co = Object::cast_to<CollisionObject2D>(o);
4141-
co->_mouse_shape_exit(e.second);
4142-
shapes_to_mouse_exit.pop_front();
4138+
co->_mouse_shape_exit(key.second);
41434139
}
41444140
}
41454141
#endif // PHYSICS_2D_DISABLED

scene/resources/2d/tile_set.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3714,68 +3714,63 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
37143714
if (p_value.is_array()) {
37153715
Array p = p_value;
37163716
Vector2i last_coord;
3717-
while (p.size() > 0) {
3718-
if (p[0].get_type() == Variant::VECTOR2) {
3719-
last_coord = p[0];
3720-
} else if (p[0].get_type() == Variant::INT) {
3721-
ctd->autotile_bitmask_flags.insert(last_coord, p[0]);
3717+
for (const Variant &elem : p) {
3718+
if (elem.get_type() == Variant::VECTOR2) {
3719+
last_coord = elem;
3720+
} else if (elem.get_type() == Variant::INT) {
3721+
ctd->autotile_bitmask_flags.insert(last_coord, elem);
37223722
}
3723-
p.pop_front();
37243723
}
37253724
}
37263725
} else if (what == "occluder_map") {
37273726
Array p = p_value;
37283727
Vector2 last_coord;
3729-
while (p.size() > 0) {
3730-
if (p[0].get_type() == Variant::VECTOR2) {
3731-
last_coord = p[0];
3732-
} else if (p[0].get_type() == Variant::OBJECT) {
3733-
ctd->autotile_occluder_map.insert(last_coord, p[0]);
3728+
for (const Variant &elem : p) {
3729+
if (elem.get_type() == Variant::VECTOR2) {
3730+
last_coord = elem;
3731+
} else if (elem.get_type() == Variant::OBJECT) {
3732+
ctd->autotile_occluder_map.insert(last_coord, elem);
37343733
}
3735-
p.pop_front();
37363734
}
37373735
} else if (what == "navpoly_map") {
37383736
Array p = p_value;
37393737
Vector2 last_coord;
3740-
while (p.size() > 0) {
3741-
if (p[0].get_type() == Variant::VECTOR2) {
3742-
last_coord = p[0];
3743-
} else if (p[0].get_type() == Variant::OBJECT) {
3738+
for (const Variant &elem : p) {
3739+
if (elem.get_type() == Variant::VECTOR2) {
3740+
last_coord = elem;
3741+
} else if (elem.get_type() == Variant::OBJECT) {
37443742
#ifndef NAVIGATION_2D_DISABLED
3745-
ctd->autotile_navpoly_map.insert(last_coord, p[0]);
3743+
ctd->autotile_navpoly_map.insert(last_coord, elem);
37463744
#endif // NAVIGATION_2D_DISABLED
37473745
}
3748-
p.pop_front();
37493746
}
37503747
} else if (what == "priority_map") {
37513748
Array p = p_value;
37523749
Vector3 val;
37533750
Vector2 v;
37543751
int priority;
3755-
while (p.size() > 0) {
3756-
val = p[0];
3752+
for (const Variant &elem : p) {
3753+
val = elem;
37573754
if (val.z > 1) {
37583755
v.x = val.x;
37593756
v.y = val.y;
37603757
priority = (int)val.z;
37613758
ctd->autotile_priority_map.insert(v, priority);
37623759
}
3763-
p.pop_front();
37643760
}
37653761
} else if (what == "z_index_map") {
37663762
Array p = p_value;
37673763
Vector3 val;
37683764
Vector2 v;
37693765
int z_index;
3770-
while (p.size() > 0) {
3771-
val = p[0];
3766+
for (const Variant &elem : p) {
3767+
val = elem;
37723768
if (val.z != 0) {
37733769
v.x = val.x;
37743770
v.y = val.y;
37753771
z_index = (int)val.z;
37763772
ctd->autotile_z_index_map.insert(v, z_index);
37773773
}
3778-
p.pop_front();
37793774
}
37803775
}
37813776

scene/resources/packed_scene.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Ref<Resource> SceneState::get_remap_resource(const Ref<Resource> &p_resource, Ha
126126

127127
Node *SceneState::instantiate(GenEditState p_edit_state) const {
128128
// Nodes where instantiation failed (because something is missing.)
129-
List<Node *> stray_instances;
129+
LocalVector<Node *> stray_instances;
130130

131131
#define NODE_FROM_ID(p_name, p_id) \
132132
Node *p_name; \
@@ -614,10 +614,10 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
614614
//Node *s = ret_nodes[0];
615615

616616
//remove nodes that could not be added, likely as a result that
617-
while (stray_instances.size()) {
618-
memdelete(stray_instances.front()->get());
619-
stray_instances.pop_front();
617+
for (Node *node : stray_instances) {
618+
memdelete(node);
620619
}
620+
stray_instances.clear();
621621

622622
for (int i = 0; i < editable_instances.size(); i++) {
623623
Node *ei = ret_nodes[0]->get_node_or_null(editable_instances[i]);

0 commit comments

Comments
 (0)