From 12186fdccc46e03a16ba0350e0c96539d894c021 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Sun, 19 Apr 2026 22:01:56 +0200 Subject: [PATCH] Keep more non-declaration initialization within the `for` loop clause --- src/gfx/pal_packing.cpp | 8 +++----- src/gfx/reverse.cpp | 3 +-- src/link/lexer.cpp | 10 ++++------ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/gfx/pal_packing.cpp b/src/gfx/pal_packing.cpp index 9600c017..06257f6d 100644 --- a/src/gfx/pal_packing.cpp +++ b/src/gfx/pal_packing.cpp @@ -328,18 +328,16 @@ static void decant(std::vector &assignments, std::vector auto attrs = from.begin(); std::advance(attrs, wasProcessed - processed.begin()); + // Build up the "component"; start by marking the first color set as processed std::unordered_set colors(RANGE(colorSets[attrs->colorSetIndex])); std::vector members = {static_cast(wasProcessed - processed.begin())}; - *wasProcessed = true; // Mark the first color set as processed - - // Build up the "component"... - for (; ++wasProcessed != processed.end(); ++attrs) { + for (*wasProcessed = true; ++wasProcessed != processed.end(); ++attrs) { // If at least one color matches, add it if (ColorSet const &colorSet = colorSets[attrs->colorSetIndex]; std::find_first_of(RANGE(colors), RANGE(colorSet)) != colors.end()) { colors.insert(RANGE(colorSet)); members.push_back(wasProcessed - processed.begin()); - *wasProcessed = true; // Mark that color set as processed + *wasProcessed = true; // Mark the added color set as processed } } diff --git a/src/gfx/reverse.cpp b/src/gfx/reverse.cpp index 8746952e..af95aa73 100644 --- a/src/gfx/reverse.cpp +++ b/src/gfx/reverse.cpp @@ -175,8 +175,7 @@ void reverse() { // Pick the smallest width that will result in a landscape-aspect rectangular image. // Thus a prime number of tiles will result in a horizontal row. // This avoids redundancy with `-r 1` which results in a vertical column. - width = static_cast(ceil(sqrt(mapSize))); - for (; width < mapSize; ++width) { + for (width = static_cast(ceil(sqrt(mapSize))); width < mapSize; ++width) { if (mapSize % width == 0) { break; } diff --git a/src/link/lexer.cpp b/src/link/lexer.cpp index 4ac24002..def7c947 100644 --- a/src/link/lexer.cpp +++ b/src/link/lexer.cpp @@ -192,15 +192,16 @@ static yy::parser::symbol_type parseAnyNumber(int c) { static yy::parser::symbol_type parseString() { LexerStackEntry &context = lexerStack.back(); - int c = context.file.sgetc(); std::string str; - for (; c != '"'; c = context.file.sgetc()) { + for (int c = context.file.sgetc();; c = context.file.sgetc()) { if (c == EOF || isNewline(c)) { scriptError("Unterminated string"); break; } context.file.sbumpc(); - if (c == '\\') { + if (c == '"') { + break; + } else if (c == '\\') { c = context.file.sgetc(); if (c == EOF || isNewline(c)) { scriptError("Unterminated string"); @@ -220,9 +221,6 @@ static yy::parser::symbol_type parseString() { } str.push_back(c); } - if (c == '"') { - context.file.sbumpc(); - } return yy::parser::make_string(std::move(str)); }