Prefer pre-inc/dec unless post-inc/dec are necessary

This commit is contained in:
Rangi42
2025-07-19 15:04:08 -04:00
parent bf69043a1d
commit 14f5e16ae8
19 changed files with 111 additions and 118 deletions

View File

@@ -58,7 +58,7 @@ static void assignSection(Section &section, MemoryLocation const &location) {
next->bank = location.bank;
}
nbSectionsToAssign--;
--nbSectionsToAssign;
out_AddSection(section);
}
@@ -151,7 +151,7 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
location.address += section.alignMask + 1 + section.alignOfs;
} else {
// Any location is fine, so, next free block
spaceIdx++;
++spaceIdx;
if (spaceIdx < bankMem.size()) {
location.address = bankMem[spaceIdx].address;
}
@@ -161,7 +161,7 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
// go forwards until that is no longer the case.
while (spaceIdx < bankMem.size()
&& location.address >= bankMem[spaceIdx].address + bankMem[spaceIdx].size) {
spaceIdx++;
++spaceIdx;
}
// Try again with the new location/free space combo
@@ -174,7 +174,7 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
return -1;
} else if (scrambleROMX && section.type == SECTTYPE_ROMX && location.bank <= scrambleROMX) {
if (location.bank > typeInfo.firstBank) {
location.bank--;
--location.bank;
} else if (scrambleROMX < typeInfo.lastBank) {
location.bank = scrambleROMX + 1;
} else {
@@ -183,7 +183,7 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
} else if (scrambleWRAMX && section.type == SECTTYPE_WRAMX
&& location.bank <= scrambleWRAMX) {
if (location.bank > typeInfo.firstBank) {
location.bank--;
--location.bank;
} else if (scrambleWRAMX < typeInfo.lastBank) {
location.bank = scrambleWRAMX + 1;
} else {
@@ -191,14 +191,14 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
}
} else if (scrambleSRAM && section.type == SECTTYPE_SRAM && location.bank <= scrambleSRAM) {
if (location.bank > typeInfo.firstBank) {
location.bank--;
--location.bank;
} else if (scrambleSRAM < typeInfo.lastBank) {
location.bank = scrambleSRAM + 1;
} else {
return -1;
}
} else if (location.bank < typeInfo.lastBank) {
location.bank++;
++location.bank;
} else {
return -1;
}
@@ -355,11 +355,11 @@ static void categorizeSection(Section &section) {
// Insert section while keeping the list sorted by decreasing size
auto pos = sections.begin();
while (pos != sections.end() && (*pos)->size > section.size) {
pos++;
++pos;
}
sections.insert(pos, &section);
nbSectionsToAssign++;
++nbSectionsToAssign;
}
void assign_AssignSections() {
@@ -395,8 +395,7 @@ void assign_AssignSections() {
constraints--) {
for (Section *section : unassignedSections[constraints]) {
fprintf(stderr, "%c \"%s\"", nbSections == 0 ? ';' : ',', section->name.c_str());
nbSections++;
if (nbSections == 10) {
if (++nbSections == 10) {
goto max_out; // Can't `break` out of a nested loop
}
}

View File

@@ -209,7 +209,7 @@ static void parseScrambleSpec(char const *spec) {
}
if (*spec == '=') {
spec++; // `strtoul` will skip the whitespace on its own
++spec; // `strtoul` will skip the whitespace on its own
unsigned long limit;
char *endptr;

View File

@@ -527,7 +527,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
sym_AddSymbol(symbol);
if (std::holds_alternative<Label>(symbol.data)) {
nbSymPerSect[std::get<Label>(symbol.data).sectionID]++;
++nbSymPerSect[std::get<Label>(symbol.data).sectionID];
}
}

View File

@@ -90,7 +90,7 @@ void out_AddSection(Section const &section) {
// Insert section while keeping the list sorted by increasing org
auto pos = bankSections.begin();
while (pos != bankSections.end() && (*pos)->org < section.org) {
pos++;
++pos;
}
bankSections.insert(pos, &section);
}
@@ -178,7 +178,7 @@ static void
// Output padding up to the next SECTION
while (offset + baseOffset < section->org) {
putc(getNextFillByte(), outputFile);
offset++;
++offset;
}
// Output the section itself
@@ -196,7 +196,7 @@ static void
if (!disablePadding) {
while (offset < size) {
putc(getNextFillByte(), outputFile);
offset++;
++offset;
}
}
}
@@ -419,7 +419,7 @@ uint16_t forEachSection(SortedSections const &sectList, F callback) {
: zeroLenSection;
used += (*pickedSection)->size;
callback(**pickedSection);
pickedSection++;
++pickedSection;
}
return used;
}

View File

@@ -52,7 +52,7 @@ static void printDiag(
static void incrementErrors() {
if (nbErrors != UINT32_MAX) {
nbErrors++;
++nbErrors;
}
}