Keep more non-declaration initialization within the for loop clause

This commit is contained in:
Rangi42
2026-04-19 22:01:56 +02:00
parent 71dfab3365
commit 12186fdccc
3 changed files with 8 additions and 13 deletions
+3 -5
View File
@@ -328,18 +328,16 @@ static void decant(std::vector<AssignedSets> &assignments, std::vector<ColorSet>
auto attrs = from.begin(); auto attrs = from.begin();
std::advance(attrs, wasProcessed - processed.begin()); std::advance(attrs, wasProcessed - processed.begin());
// Build up the "component"; start by marking the first color set as processed
std::unordered_set<uint16_t> colors(RANGE(colorSets[attrs->colorSetIndex])); std::unordered_set<uint16_t> colors(RANGE(colorSets[attrs->colorSetIndex]));
std::vector<size_t> members = {static_cast<size_t>(wasProcessed - processed.begin())}; std::vector<size_t> members = {static_cast<size_t>(wasProcessed - processed.begin())};
*wasProcessed = true; // Mark the first color set as processed for (*wasProcessed = true; ++wasProcessed != processed.end(); ++attrs) {
// Build up the "component"...
for (; ++wasProcessed != processed.end(); ++attrs) {
// If at least one color matches, add it // If at least one color matches, add it
if (ColorSet const &colorSet = colorSets[attrs->colorSetIndex]; if (ColorSet const &colorSet = colorSets[attrs->colorSetIndex];
std::find_first_of(RANGE(colors), RANGE(colorSet)) != colors.end()) { std::find_first_of(RANGE(colors), RANGE(colorSet)) != colors.end()) {
colors.insert(RANGE(colorSet)); colors.insert(RANGE(colorSet));
members.push_back(wasProcessed - processed.begin()); members.push_back(wasProcessed - processed.begin());
*wasProcessed = true; // Mark that color set as processed *wasProcessed = true; // Mark the added color set as processed
} }
} }
+1 -2
View File
@@ -175,8 +175,7 @@ void reverse() {
// Pick the smallest width that will result in a landscape-aspect rectangular image. // 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. // Thus a prime number of tiles will result in a horizontal row.
// This avoids redundancy with `-r 1` which results in a vertical column. // This avoids redundancy with `-r 1` which results in a vertical column.
width = static_cast<size_t>(ceil(sqrt(mapSize))); for (width = static_cast<size_t>(ceil(sqrt(mapSize))); width < mapSize; ++width) {
for (; width < mapSize; ++width) {
if (mapSize % width == 0) { if (mapSize % width == 0) {
break; break;
} }
+4 -6
View File
@@ -192,15 +192,16 @@ static yy::parser::symbol_type parseAnyNumber(int c) {
static yy::parser::symbol_type parseString() { static yy::parser::symbol_type parseString() {
LexerStackEntry &context = lexerStack.back(); LexerStackEntry &context = lexerStack.back();
int c = context.file.sgetc();
std::string str; std::string str;
for (; c != '"'; c = context.file.sgetc()) { for (int c = context.file.sgetc();; c = context.file.sgetc()) {
if (c == EOF || isNewline(c)) { if (c == EOF || isNewline(c)) {
scriptError("Unterminated string"); scriptError("Unterminated string");
break; break;
} }
context.file.sbumpc(); context.file.sbumpc();
if (c == '\\') { if (c == '"') {
break;
} else if (c == '\\') {
c = context.file.sgetc(); c = context.file.sgetc();
if (c == EOF || isNewline(c)) { if (c == EOF || isNewline(c)) {
scriptError("Unterminated string"); scriptError("Unterminated string");
@@ -220,9 +221,6 @@ static yy::parser::symbol_type parseString() {
} }
str.push_back(c); str.push_back(c);
} }
if (c == '"') {
context.file.sbumpc();
}
return yy::parser::make_string(std::move(str)); return yy::parser::make_string(std::move(str));
} }