Prefer pre-increment/decrement operators in for loops

This commit is contained in:
Rangi42
2025-07-24 18:08:17 -04:00
parent c6d0e8de63
commit d6a28a6259
15 changed files with 48 additions and 48 deletions

View File

@@ -370,7 +370,7 @@ int main(int argc, char *argv[]) {
}
// Read all object files first,
for (obj_Setup(argc - curArgIndex); curArgIndex < argc; curArgIndex++) {
for (obj_Setup(argc - curArgIndex); curArgIndex < argc; ++curArgIndex) {
obj_ReadFile(argv[curArgIndex], argc - curArgIndex - 1);
}

View File

@@ -126,7 +126,7 @@ static void readFileStackNode(
depth, file, "%s: Cannot read node #%" PRIu32 "'s rept depth: %s", fileName, nodeID
);
node.data = std::vector<uint32_t>(depth);
for (uint32_t i = 0; i < depth; i++) {
for (uint32_t i = 0; i < depth; ++i) {
tryReadLong(
node.iters()[i],
file,
@@ -389,7 +389,7 @@ static void readSection(
);
section.patches.resize(nbPatches);
for (uint32_t i = 0; i < nbPatches; i++) {
for (uint32_t i = 0; i < nbPatches; ++i) {
readPatch(file, section.patches[i], fileName, section.name, i, fileNodes);
}
}
@@ -516,7 +516,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
std::vector<uint32_t> nbSymPerSect(nbSections, 0);
verbosePrint("Reading %" PRIu32 " symbols...\n", nbSymbols);
for (uint32_t i = 0; i < nbSymbols; i++) {
for (uint32_t i = 0; i < nbSymbols; ++i) {
// Read symbol
Symbol &symbol = fileSymbols[i];
@@ -532,7 +532,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
std::vector<std::unique_ptr<Section>> fileSections(nbSections);
verbosePrint("Reading %" PRIu32 " sections...\n", nbSections);
for (uint32_t i = 0; i < nbSections; i++) {
for (uint32_t i = 0; i < nbSections; ++i) {
// Read section
fileSections[i] = std::make_unique<Section>();
fileSections[i]->nextu = nullptr;
@@ -544,7 +544,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
uint32_t nbAsserts;
tryReadLong(nbAsserts, file, "%s: Cannot read number of assertions: %s", fileName);
verbosePrint("Reading %" PRIu32 " assertions...\n", nbAsserts);
for (uint32_t i = 0; i < nbAsserts; i++) {
for (uint32_t i = 0; i < nbAsserts; ++i) {
Assertion &assertion = patch_AddAssertion();
readAssertion(file, assertion, fileName, i, nodes[fileID]);
@@ -553,7 +553,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
}
// Give patches' PC section pointers to their sections
for (uint32_t i = 0; i < nbSections; i++) {
for (uint32_t i = 0; i < nbSections; ++i) {
if (sect_HasData(fileSections[i]->type)) {
for (Patch &patch : fileSections[i]->patches) {
linkPatchToPCSect(patch, fileSections);
@@ -562,7 +562,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
}
// Give symbols' section pointers to their sections
for (uint32_t i = 0; i < nbSymbols; i++) {
for (uint32_t i = 0; i < nbSymbols; ++i) {
if (std::holds_alternative<Label>(fileSymbols[i].data)) {
Label &label = std::get<Label>(fileSymbols[i].data);
label.section = fileSections[label.sectionID].get();
@@ -572,14 +572,14 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
}
// Calling `sect_AddSection` invalidates the contents of `fileSections`!
for (uint32_t i = 0; i < nbSections; i++) {
for (uint32_t i = 0; i < nbSections; ++i) {
sect_AddSection(std::move(fileSections[i]));
}
// Fix symbols' section pointers to component sections
// This has to run **after** all the `sect_AddSection()` calls,
// so that `sect_GetSection()` will work
for (uint32_t i = 0; i < nbSymbols; i++) {
for (uint32_t i = 0; i < nbSymbols; ++i) {
if (std::holds_alternative<Label>(fileSymbols[i].data)) {
Label &label = std::get<Label>(fileSymbols[i].data);
Section *section = label.section;

View File

@@ -79,7 +79,7 @@ void out_AddSection(Section const &section) {
);
}
for (uint32_t i = sections[section.type].size(); i < minNbBanks; i++) {
for (uint32_t i = sections[section.type].size(); i < minNbBanks; ++i) {
sections[section.type].emplace_back();
}
@@ -146,7 +146,7 @@ static void coverOverlayBanks(uint32_t nbOverlayBanks) {
: 0;
if (nbUncoveredBanks > sections[SECTTYPE_ROMX].size()) {
for (uint32_t i = sections[SECTTYPE_ROMX].size(); i < nbUncoveredBanks; i++) {
for (uint32_t i = sections[SECTTYPE_ROMX].size(); i < nbUncoveredBanks; ++i) {
sections[SECTTYPE_ROMX].emplace_back();
}
}
@@ -189,7 +189,7 @@ static void
continue;
}
// Skip bytes even with pipes
for (uint16_t i = 0; i < section->size; i++) {
for (uint16_t i = 0; i < section->size; ++i) {
getc(overlayFile);
}
}
@@ -255,7 +255,7 @@ static void writeROM() {
sectionTypeInfo[SECTTYPE_ROM0].size
);
for (uint32_t i = 0; i < sections[SECTTYPE_ROMX].size(); i++) {
for (uint32_t i = 0; i < sections[SECTTYPE_ROMX].size(); ++i) {
writeBank(
&sections[SECTTYPE_ROMX][i].sections,
sectionTypeInfo[SECTTYPE_ROMX].startAddr,
@@ -498,7 +498,7 @@ static void writeMapBank(SortedSections const &sectList, SectionType type, uint3
static void writeMapSummary() {
fputs("SUMMARY:\n", mapFile);
for (uint8_t i = 0; i < SECTTYPE_INVALID; i++) {
for (uint8_t i = 0; i < SECTTYPE_INVALID; ++i) {
SectionType type = typeMap[i];
uint32_t nbBanks = sections[type].size();
@@ -514,7 +514,7 @@ static void writeMapSummary() {
uint32_t usedTotal = 0;
for (uint32_t bank = 0; bank < nbBanks; bank++) {
for (uint32_t bank = 0; bank < nbBanks; ++bank) {
usedTotal += forEachSection(sections[type][bank], [](Section const &) {});
}
@@ -552,10 +552,10 @@ static void writeSym() {
fputs("; File generated by rgblink\n", symFile);
for (uint8_t i = 0; i < SECTTYPE_INVALID; i++) {
for (uint8_t i = 0; i < SECTTYPE_INVALID; ++i) {
SectionType type = typeMap[i];
for (uint32_t bank = 0; bank < sections[type].size(); bank++) {
for (uint32_t bank = 0; bank < sections[type].size(); ++bank) {
writeSymBank(sections[type][bank], type, bank);
}
}
@@ -602,10 +602,10 @@ static void writeMap() {
writeMapSummary();
for (uint8_t i = 0; i < SECTTYPE_INVALID; i++) {
for (uint8_t i = 0; i < SECTTYPE_INVALID; ++i) {
SectionType type = typeMap[i];
for (uint32_t bank = 0; bank < sections[type].size(); bank++) {
for (uint32_t bank = 0; bank < sections[type].size(); ++bank) {
writeMapBank(sections[type][bank], type, bank);
}
}

View File

@@ -557,7 +557,7 @@ static void applyFilePatches(Section &section, Section &dataSection) {
type.size * 8U
);
}
for (uint8_t i = 0; i < type.size; i++) {
for (uint8_t i = 0; i < type.size; ++i) {
dataSection.data[offset + i] = value & 0xFF;
value >>= 8;
}