diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2020-12-07 14:21:11 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2020-12-07 14:41:17 +0300 |
commit | 11c4066159e12ff630673c5fd94b37fb8c0f9102 (patch) | |
tree | 79c365fe59bf852478c561c1a7fd1679831a2be7 /source/blender/io | |
parent | 2072134faadf4fd901c88ed7440e2289d61e0299 (diff) |
Cleanup: partial Clang-Tidy modernize-loop-convert
Modernize loops by using the `for(type variable : container)` syntax.
Some loops were trivial to fix, whereas others required more attention
to avoid semantic changes. I couldn't address all old-style loops, so
this commit doesn't enable the `modernize-loop-convert` rule.
Although Clang-Tidy's auto-fixer prefers to use `auto` for the loop
variable declaration, I made as many declarations as possible explicit.
To me this increases local readability, as you don't need to fully
understand the container in order to understand the loop variable type.
No functional changes.
Diffstat (limited to 'source/blender/io')
-rw-r--r-- | source/blender/io/alembic/intern/abc_reader_mesh.cc | 4 | ||||
-rw-r--r-- | source/blender/io/collada/AnimationImporter.cpp | 9 | ||||
-rw-r--r-- | source/blender/io/collada/BCMath.cpp | 14 | ||||
-rw-r--r-- | source/blender/io/collada/BlenderContext.cpp | 4 | ||||
-rw-r--r-- | source/blender/io/collada/ControllerExporter.cpp | 14 | ||||
-rw-r--r-- | source/blender/io/collada/DocumentImporter.cpp | 15 | ||||
-rw-r--r-- | source/blender/io/collada/MeshImporter.cpp | 11 | ||||
-rw-r--r-- | source/blender/io/collada/SceneExporter.cpp | 3 | ||||
-rw-r--r-- | source/blender/io/collada/collada_internal.cpp | 3 | ||||
-rw-r--r-- | source/blender/io/collada/collada_utils.cpp | 12 |
10 files changed, 34 insertions, 55 deletions
diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index 14c3d756d56..0b9636ffb70 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -724,9 +724,7 @@ void AbcMeshReader::assign_facesets_to_mpoly(const ISampleSelector &sample_sel, int current_mat = 0; - for (int i = 0; i < face_sets.size(); i++) { - const std::string &grp_name = face_sets[i]; - + for (const std::string &grp_name : face_sets) { if (r_mat_map.find(grp_name) == r_mat_map.end()) { r_mat_map[grp_name] = ++current_mat; } diff --git a/source/blender/io/collada/AnimationImporter.cpp b/source/blender/io/collada/AnimationImporter.cpp index 850b6a813ed..77ccdeae28d 100644 --- a/source/blender/io/collada/AnimationImporter.cpp +++ b/source/blender/io/collada/AnimationImporter.cpp @@ -272,9 +272,8 @@ void AnimationImporter::add_fcurves_to_object(Main *bmain, AnimationImporter::~AnimationImporter() { /* free unused FCurves */ - for (std::vector<FCurve *>::iterator it = unused_curves.begin(); it != unused_curves.end(); - it++) { - BKE_fcurve_free(*it); + for (FCurve *unused_curve : unused_curves) { + BKE_fcurve_free(unused_curve); } if (!unused_curves.empty()) { @@ -2035,8 +2034,8 @@ bool AnimationImporter::evaluate_animation(COLLADAFW::Transformation *tm, COLLADABU::Math::Matrix4 matrix; int mi = 0, mj = 0; - for (std::vector<FCurve *>::iterator it = curves.begin(); it != curves.end(); it++) { - matrix.setElement(mi, mj, evaluate_fcurve(*it, fra)); + for (FCurve *curve : curves) { + matrix.setElement(mi, mj, evaluate_fcurve(curve, fra)); mj++; if (mj == 4) { mi++; diff --git a/source/blender/io/collada/BCMath.cpp b/source/blender/io/collada/BCMath.cpp index 8a3fbf3c92c..7d8e5825ac9 100644 --- a/source/blender/io/collada/BCMath.cpp +++ b/source/blender/io/collada/BCMath.cpp @@ -157,20 +157,20 @@ void BCMatrix::transpose(Matrix &mat) void BCMatrix::sanitize(Matrix &mat, int precision) { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - double val = (double)mat[i][j]; + for (auto &row : mat) { + for (float &cell : row) { + double val = (double)cell; val = double_round(val, precision); - mat[i][j] = (float)val; + cell = (float)val; } } } void BCMatrix::sanitize(DMatrix &mat, int precision) { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - mat[i][j] = double_round(mat[i][j], precision); + for (auto &row : mat) { + for (float &cell : row) { + cell = double_round(cell, precision); } } } diff --git a/source/blender/io/collada/BlenderContext.cpp b/source/blender/io/collada/BlenderContext.cpp index 8009f10aa03..ab420e79ba7 100644 --- a/source/blender/io/collada/BlenderContext.cpp +++ b/source/blender/io/collada/BlenderContext.cpp @@ -81,8 +81,8 @@ bool bc_is_in_Export_set(LinkNode *export_set, Object *ob, ViewLayer *view_layer std::vector<Object *> children; bc_get_children(children, ob, view_layer); - for (int i = 0; i < children.size(); i++) { - if (bc_is_in_Export_set(export_set, children[i], view_layer)) { + for (Object *child : children) { + if (bc_is_in_Export_set(export_set, child, view_layer)) { to_export = true; break; } diff --git a/source/blender/io/collada/ControllerExporter.cpp b/source/blender/io/collada/ControllerExporter.cpp index 52d4bbf122e..6f0d422dbe2 100644 --- a/source/blender/io/collada/ControllerExporter.cpp +++ b/source/blender/io/collada/ControllerExporter.cpp @@ -245,9 +245,9 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm) if (sumw > 0.0f) { float invsumw = 1.0f / sumw; vcounts.push_back(jw.size()); - for (std::map<int, float>::iterator m = jw.begin(); m != jw.end(); ++m) { - joints.push_back((*m).first); - weights.push_back(invsumw * (*m).second); + for (auto &index_and_weight : jw) { + joints.push_back(index_and_weight.first); + weights.push_back(invsumw * index_and_weight.second); } } else { @@ -596,8 +596,8 @@ std::string ControllerExporter::add_weights_source(Mesh *me, source.prepareToAppendValues(); - for (std::list<float>::const_iterator i = weights.begin(); i != weights.end(); ++i) { - source.appendValues(*i); + for (float weight : weights) { + source.appendValues(weight); } source.finish(); @@ -638,8 +638,8 @@ void ControllerExporter::add_vertex_weights_element(const std::string &weights_s /* write deformer index - weight index pairs */ int weight_index = 0; - for (std::list<int>::const_iterator i = joints.begin(); i != joints.end(); ++i) { - weightselem.appendValues(*i, weight_index++); + for (int joint_index : joints) { + weightselem.appendValues(joint_index, weight_index++); } weightselem.finish(); diff --git a/source/blender/io/collada/DocumentImporter.cpp b/source/blender/io/collada/DocumentImporter.cpp index b85a96d89de..10c1a90576c 100644 --- a/source/blender/io/collada/DocumentImporter.cpp +++ b/source/blender/io/collada/DocumentImporter.cpp @@ -241,10 +241,8 @@ void DocumentImporter::finish() armature_importer.fix_animation(); #endif - for (std::vector<const COLLADAFW::VisualScene *>::iterator vsit = vscenes.begin(); - vsit != vscenes.end(); - vsit++) { - const COLLADAFW::NodePointerArray &roots = (*vsit)->getRootNodes(); + for (const COLLADAFW::VisualScene *vscene : vscenes) { + const COLLADAFW::NodePointerArray &roots = vscene->getRootNodes(); for (unsigned int i = 0; i < roots.getCount(); i++) { translate_anim_recursive(roots[i], nullptr, nullptr); @@ -665,9 +663,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, goto finally; } - for (std::vector<Object *>::iterator it = objects_done->begin(); it != objects_done->end(); - ++it) { - ob = *it; + for (Object *ob : *objects_done) { std::string nodename = node->getName().empty() ? node->getOriginalId() : node->getName(); BKE_libblock_rename(bmain, &ob->id, (char *)nodename.c_str()); object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), ob)); @@ -681,10 +677,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, /* create_constraints(et,ob); */ } - for (std::vector<Object *>::iterator it = objects_done->begin(); it != objects_done->end(); - ++it) { - ob = *it; - + for (Object *ob : *objects_done) { if (read_transform) { anim_importer.read_node_transform(node, ob); /* overwrites location set earlier */ } diff --git a/source/blender/io/collada/MeshImporter.cpp b/source/blender/io/collada/MeshImporter.cpp index bb2aabb0598..2934ea1caa6 100644 --- a/source/blender/io/collada/MeshImporter.cpp +++ b/source/blender/io/collada/MeshImporter.cpp @@ -973,9 +973,7 @@ static void bc_remove_materials_from_object(Object *ob, Mesh *me) std::vector<Object *> MeshImporter::get_all_users_of(Mesh *reference_mesh) { std::vector<Object *> mesh_users; - for (std::vector<Object *>::iterator it = imported_objects.begin(); it != imported_objects.end(); - ++it) { - Object *ob = (*it); + for (Object *ob : imported_objects) { if (bc_is_marked(ob)) { bc_remove_mark(ob); Mesh *me = (Mesh *)ob->data; @@ -1007,9 +1005,7 @@ std::vector<Object *> MeshImporter::get_all_users_of(Mesh *reference_mesh) */ void MeshImporter::optimize_material_assignements() { - for (std::vector<Object *>::iterator it = imported_objects.begin(); it != imported_objects.end(); - ++it) { - Object *ob = (*it); + for (Object *ob : imported_objects) { Mesh *me = (Mesh *)ob->data; if (ID_REAL_USERS(&me->id) == 1) { bc_copy_materials_to_data(ob, me); @@ -1029,8 +1025,7 @@ void MeshImporter::optimize_material_assignements() } if (can_move) { bc_copy_materials_to_data(ref_ob, me); - for (int index = 0; index < mesh_users.size(); index++) { - Object *object = mesh_users[index]; + for (Object *object : mesh_users) { bc_remove_materials_from_object(object, me); bc_remove_mark(object); } diff --git a/source/blender/io/collada/SceneExporter.cpp b/source/blender/io/collada/SceneExporter.cpp index 01c270518e9..5bbd22b8275 100644 --- a/source/blender/io/collada/SceneExporter.cpp +++ b/source/blender/io/collada/SceneExporter.cpp @@ -86,8 +86,7 @@ void SceneExporter::writeNodeList(std::vector<Object *> &child_objects, Object * * I really prefer to enforce the export of hidden * elements in an object hierarchy. When the children of * the hidden elements are exported as well. */ - for (int i = 0; i < child_objects.size(); i++) { - Object *child = child_objects[i]; + for (auto *child : child_objects) { writeNode(child); if (bc_is_marked(child)) { bc_remove_mark(child); diff --git a/source/blender/io/collada/collada_internal.cpp b/source/blender/io/collada/collada_internal.cpp index 096f6a678ac..ed5cc62d05f 100644 --- a/source/blender/io/collada/collada_internal.cpp +++ b/source/blender/io/collada/collada_internal.cpp @@ -280,8 +280,7 @@ std::string encode_xml(std::string xml) std::map<char, std::string>::const_iterator it; std::string encoded_xml; - for (unsigned int i = 0; i < xml.size(); i++) { - char c = xml.at(i); + for (char c : xml) { it = escape.find(c); if (it == escape.end()) { diff --git a/source/blender/io/collada/collada_utils.cpp b/source/blender/io/collada/collada_utils.cpp index c57952afcc8..25c10c717e2 100644 --- a/source/blender/io/collada/collada_utils.cpp +++ b/source/blender/io/collada/collada_utils.cpp @@ -379,11 +379,9 @@ void bc_match_scale(std::vector<Object *> *objects_done, UnitConverter &bc_unit, bool scale_to_scene) { - for (std::vector<Object *>::iterator it = objects_done->begin(); it != objects_done->end(); - ++it) { - Object *ob = *it; + for (Object *ob : *objects_done) { if (ob->parent == nullptr) { - bc_match_scale(*it, bc_unit, scale_to_scene); + bc_match_scale(ob, bc_unit, scale_to_scene); } } } @@ -524,10 +522,8 @@ BoneExtensionManager::~BoneExtensionManager() std::map<std::string, BoneExtensionMap *>::iterator map_it; for (map_it = extended_bone_maps.begin(); map_it != extended_bone_maps.end(); ++map_it) { BoneExtensionMap *extended_bones = map_it->second; - for (BoneExtensionMap::iterator ext_it = extended_bones->begin(); - ext_it != extended_bones->end(); - ++ext_it) { - delete ext_it->second; + for (auto &extended_bone : *extended_bones) { + delete extended_bone.second; } extended_bones->clear(); delete extended_bones; |