Skip to content

Commit a4ce306

Browse files
committed
Convert while-pop_front loop to iterator loop.
1 parent 1f56d96 commit a4ce306

15 files changed

+66
-94
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/math/quick_hull.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,10 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) {
426426
bool skip_setter_getter_methods = true;
427427

428428
// Populate documentation data for each exposed class.
429-
while (classes.size()) {
430-
const String &name = classes.front()->get();
429+
for (const StringName &class_name : classes) {
430+
const String &name = class_name;
431431
if (!ClassDB::is_class_exposed(name)) {
432432
print_verbose(vformat("Class '%s' is not exposed, skipping.", name));
433-
classes.pop_front();
434433
continue;
435434
}
436435

@@ -735,9 +734,8 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) {
735734

736735
c.theme_properties.sort();
737736
}
738-
739-
classes.pop_front();
740737
}
738+
classes.clear();
741739
}
742740

743741
if (p_flags.has_flag(GENERATE_FLAG_SKIP_BASIC_TYPES)) {
@@ -1274,9 +1272,8 @@ Error DocTools::erase_classes(const String &p_dir) {
12741272
}
12751273
da->list_dir_end();
12761274

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

12821279
return OK;

editor/plugins/asset_library_editor_plugin.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

modules/mono/editor/bindings_generator.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3866,31 +3866,25 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
38663866
ClassDB::get_class_list(&class_list);
38673867
class_list.sort_custom<StringName::AlphCompare>();
38683868

3869-
while (class_list.size()) {
3870-
StringName type_cname = class_list.front()->get();
3871-
3869+
for (const StringName &type_cname : class_list) {
38723870
ClassDB::APIType api_type = ClassDB::get_api_type(type_cname);
38733871

38743872
if (api_type == ClassDB::API_NONE) {
3875-
class_list.pop_front();
38763873
continue;
38773874
}
38783875

38793876
if (ignored_types.has(type_cname)) {
38803877
_log("Ignoring type '%s' because it's in the list of ignored types\n", String(type_cname).utf8().get_data());
3881-
class_list.pop_front();
38823878
continue;
38833879
}
38843880

38853881
if (!ClassDB::is_class_exposed(type_cname)) {
38863882
_log("Ignoring type '%s' because it's not exposed\n", String(type_cname).utf8().get_data());
3887-
class_list.pop_front();
38883883
continue;
38893884
}
38903885

38913886
if (!ClassDB::is_class_enabled(type_cname)) {
38923887
_log("Ignoring type '%s' because it's not enabled\n", String(type_cname).utf8().get_data());
3893-
class_list.pop_front();
38943888
continue;
38953889
}
38963890

@@ -4451,8 +4445,6 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
44514445

44524446
obj_types.insert(itype.name + CS_SINGLETON_INSTANCE_SUFFIX, itype);
44534447
}
4454-
4455-
class_list.pop_front();
44564448
}
44574449

44584450
return true;

scene/animation/animation_mixer.cpp

Lines changed: 3 additions & 4 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"
@@ -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_mixer.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ class AnimationMixer : public Node {
109109
List<StringName> animations;
110110
get_animation_list(&animations);
111111
Vector<String> ret;
112-
while (animations.size()) {
113-
ret.push_back(animations.front()->get());
114-
animations.pop_front();
112+
for (const StringName &anim : animations) {
113+
ret.push_back(anim);
115114
}
116115
return ret;
117116
}

scene/animation/animation_player.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,8 @@ void AnimationPlayer::_animation_removed(const StringName &p_name, const StringN
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

@@ -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: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4095,10 +4095,10 @@ 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.
41044104
List<Pair<ObjectID, int>> shapes_to_erase;
@@ -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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,10 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
613613
//Node *s = ret_nodes[0];
614614

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

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

servers/rendering/storage/utilities.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ class DependencyTracker {
8383
void update_end() { //call after updating dependencies
8484
List<Pair<Dependency *, DependencyTracker *>> to_clean_up;
8585

86-
for (Dependency *E : dependencies) {
87-
Dependency *dep = E;
86+
for (Dependency *dep : dependencies) {
8887
HashMap<DependencyTracker *, uint32_t>::Iterator F = dep->instances.find(this);
8988
ERR_CONTINUE(!F);
9089
if (F->value != instance_version) {
@@ -95,16 +94,14 @@ class DependencyTracker {
9594
}
9695
}
9796

98-
while (to_clean_up.size()) {
99-
to_clean_up.front()->get().first->instances.erase(to_clean_up.front()->get().second);
100-
dependencies.erase(to_clean_up.front()->get().first);
101-
to_clean_up.pop_front();
97+
for (const Pair<Dependency *, DependencyTracker *> &pair : to_clean_up) {
98+
pair.first->instances.erase(pair.second);
99+
dependencies.erase(pair.first);
102100
}
103101
}
104102

105103
void clear() { // clear all dependencies
106-
for (Dependency *E : dependencies) {
107-
Dependency *dep = E;
104+
for (Dependency *dep : dependencies) {
108105
dep->instances.erase(this);
109106
}
110107
dependencies.clear();

0 commit comments

Comments
 (0)