From 11c4066159e12ff630673c5fd94b37fb8c0f9102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 7 Dec 2020 12:21:11 +0100 Subject: 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. --- source/blender/imbuf/intern/dds/BlockDXT.cpp | 4 +- source/blender/imbuf/intern/dds/ColorBlock.cpp | 16 +++---- .../blender/imbuf/intern/openexr/openexr_api.cpp | 51 ++++++++++------------ 3 files changed, 32 insertions(+), 39 deletions(-) (limited to 'source/blender/imbuf') diff --git a/source/blender/imbuf/intern/dds/BlockDXT.cpp b/source/blender/imbuf/intern/dds/BlockDXT.cpp index 2d9c300a147..4e4fca864a0 100644 --- a/source/blender/imbuf/intern/dds/BlockDXT.cpp +++ b/source/blender/imbuf/intern/dds/BlockDXT.cpp @@ -608,8 +608,8 @@ void mem_read(Stream &mem, BlockDXT1 &block) void mem_read(Stream &mem, AlphaBlockDXT3 &block) { - for (unsigned int i = 0; i < 4; i++) { - mem_read(mem, block.row[i]); + for (unsigned short &alpha : block.row) { + mem_read(mem, alpha); } } diff --git a/source/blender/imbuf/intern/dds/ColorBlock.cpp b/source/blender/imbuf/intern/dds/ColorBlock.cpp index 7c8b7c1d345..00fa0111d1c 100644 --- a/source/blender/imbuf/intern/dds/ColorBlock.cpp +++ b/source/blender/imbuf/intern/dds/ColorBlock.cpp @@ -150,12 +150,12 @@ static inline uint8 component(Color32 c, uint i) void ColorBlock::swizzle(uint x, uint y, uint z, uint w) { - for (int i = 0; i < 16; i++) { - Color32 c = m_color[i]; - m_color[i].r = component(c, x); - m_color[i].g = component(c, y); - m_color[i].b = component(c, z); - m_color[i].a = component(c, w); + for (Color32 &color : m_color) { + const Color32 c = color; + color.r = component(c, x); + color.g = component(c, y); + color.b = component(c, z); + color.a = component(c, w); } } @@ -243,8 +243,8 @@ Color32 ColorBlock::averageColor() const /** Return true if the block is not fully opaque. */ bool ColorBlock::hasAlpha() const { - for (uint i = 0; i < 16; i++) { - if (m_color[i].a != 255) { + for (const auto &i : m_color) { + if (i.a != 255) { return true; } } diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index 087e001b0b3..12faa48c81c 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -733,8 +733,8 @@ static void imb_exr_get_views(MultiPartInputFile &file, StringVector &views) if (exr_has_multipart_file(file) == false) { if (exr_has_multiview(file)) { StringVector sv = multiView(file.header(0)); - for (StringVector::const_iterator i = sv.begin(); i != sv.end(); ++i) { - views.push_back(*i); + for (const std::string &view_name : sv) { + views.push_back(view_name); } } } @@ -991,21 +991,15 @@ int IMB_exr_begin_read(void *handle, const char *filename, int *width, int *heig std::vector channels; GetChannelsInMultiPartFile(*data->ifile, channels); - for (size_t i = 0; i < channels.size(); i++) { - IMB_exr_add_channel(data, - nullptr, - channels[i].name.c_str(), - channels[i].view.c_str(), - 0, - 0, - nullptr, - false); + for (const MultiViewChannelName &channel : channels) { + IMB_exr_add_channel( + data, nullptr, channel.name.c_str(), channel.view.c_str(), 0, 0, nullptr, false); echan = (ExrChannel *)data->channels.last; - echan->m->name = channels[i].name; - echan->m->view = channels[i].view; - echan->m->part_number = channels[i].part_number; - echan->m->internal_name = channels[i].internal_name; + echan->m->name = channel.name; + echan->m->view = channel.view; + echan->m->part_number = channel.part_number; + echan->m->internal_name = channel.internal_name; } return 1; @@ -1311,9 +1305,8 @@ void IMB_exr_multilayer_convert(void *handle, } else { /* add views to RenderResult */ - for (StringVector::const_iterator i = data->multiView->begin(); i != data->multiView->end(); - ++i) { - addview(base, (*i).c_str()); + for (const std::string &view_name : *data->multiView) { + addview(base, view_name.c_str()); } } @@ -1554,15 +1547,15 @@ static ExrHandle *imb_exr_begin_read_mem(IStream &file_stream, imb_exr_get_views(*data->ifile, *data->multiView); - for (size_t i = 0; i < channels.size(); i++) { + for (const MultiViewChannelName &channel : channels) { IMB_exr_add_channel( - data, nullptr, channels[i].name.c_str(), channels[i].view.c_str(), 0, 0, nullptr, false); + data, nullptr, channel.name.c_str(), channel.view.c_str(), 0, 0, nullptr, false); echan = (ExrChannel *)data->channels.last; - echan->m->name = channels[i].name; - echan->m->view = channels[i].view; - echan->m->part_number = channels[i].part_number; - echan->m->internal_name = channels[i].internal_name; + echan->m->name = channel.name; + echan->m->view = channel.view; + echan->m->part_number = channel.part_number; + echan->m->internal_name = channel.internal_name; } /* now try to sort out how to assign memory to the channels */ @@ -1689,8 +1682,8 @@ static void exr_print_filecontents(MultiPartInputFile &file) const StringVector views = multiView(file.header(0)); printf("OpenEXR-load: MultiView file\n"); printf("OpenEXR-load: Default view: %s\n", defaultViewName(views).c_str()); - for (StringVector::const_iterator i = views.begin(); i != views.end(); ++i) { - printf("OpenEXR-load: Found view %s\n", (*i).c_str()); + for (const std::string &view : views) { + printf("OpenEXR-load: Found view %s\n", view.c_str()); } } else if (numparts > 1) { @@ -1835,10 +1828,10 @@ static void imb_exr_type_by_channels(ChannelList &channels, * with non-empty ones in the file. */ for (ChannelList::ConstIterator i = channels.begin(); i != channels.end(); i++) { - for (std::set::iterator i = layerNames.begin(); i != layerNames.end(); i++) { + for (const std::string &layer_name : layerNames) { /* see if any layername differs from a viewname */ - if (imb_exr_get_multiView_id(views, *i) == -1) { - std::string layerName = *i; + if (imb_exr_get_multiView_id(views, layer_name) == -1) { + std::string layerName = layer_name; size_t pos = layerName.rfind('.'); if (pos == std::string::npos) { -- cgit v1.2.3