mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Prefer pre-inc/dec unless post-inc/dec are necessary
This commit is contained in:
@@ -238,13 +238,13 @@ size_t charmap_ConvertNext(std::string_view &input, std::vector<int32_t> *output
|
||||
break;
|
||||
}
|
||||
|
||||
inputIdx++; // Consume that char
|
||||
++inputIdx; // Consume that char
|
||||
|
||||
if (charmap.nodes[nodeIdx].isTerminal()) {
|
||||
matchIdx = nodeIdx; // This node matches, register it
|
||||
rewindDistance = 0; // If no longer match is found, rewind here
|
||||
} else {
|
||||
rewindDistance++;
|
||||
++rewindDistance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ size_t charmap_ConvertNext(std::string_view &input, std::vector<int32_t> *output
|
||||
codepointLen = 1;
|
||||
break;
|
||||
}
|
||||
codepointLen++;
|
||||
++codepointLen;
|
||||
if (state == UTF8_ACCEPT) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ bool yywrap() {
|
||||
}
|
||||
}
|
||||
// Advance to the next iteration
|
||||
fileInfoIters.front()++;
|
||||
++fileInfoIters.front();
|
||||
// If this wasn't the last iteration, wrap instead of popping
|
||||
if (fileInfoIters.front() <= context.nbReptIters) {
|
||||
lexer_RestartRept(context.fileInfo->lineNo);
|
||||
|
||||
@@ -373,7 +373,7 @@ void LexerState::clear(uint32_t lineNo_) {
|
||||
}
|
||||
|
||||
static void nextLine() {
|
||||
lexerState->lineNo++;
|
||||
++lexerState->lineNo;
|
||||
}
|
||||
|
||||
uint32_t lexer_GetIFDepth() {
|
||||
@@ -501,7 +501,7 @@ LexerState::~LexerState() {
|
||||
|
||||
bool Expansion::advance() {
|
||||
assume(offset <= size());
|
||||
offset++;
|
||||
++offset;
|
||||
return offset > size();
|
||||
}
|
||||
|
||||
@@ -511,12 +511,11 @@ BufferedContent::~BufferedContent() {
|
||||
|
||||
void BufferedContent::advance() {
|
||||
assume(offset < std::size(buf));
|
||||
offset++;
|
||||
if (offset == std::size(buf)) {
|
||||
if (++offset == std::size(buf)) {
|
||||
offset = 0; // Wrap around if necessary
|
||||
}
|
||||
if (size > 0) {
|
||||
size--;
|
||||
--size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -810,11 +809,11 @@ static int peek() {
|
||||
return c;
|
||||
}
|
||||
|
||||
lexerState->macroArgScanDistance++; // Do not consider again
|
||||
++lexerState->macroArgScanDistance; // Do not consider again
|
||||
|
||||
if (c == '\\' && !lexerState->disableMacroArgs) {
|
||||
// If character is a backslash, check for a macro arg
|
||||
lexerState->macroArgScanDistance++;
|
||||
++lexerState->macroArgScanDistance;
|
||||
c = lexerState->peekCharAhead();
|
||||
if (isMacroChar(c)) {
|
||||
shiftChar();
|
||||
@@ -854,10 +853,10 @@ static void shiftChar() {
|
||||
if (lexerState->captureBuf) {
|
||||
lexerState->captureBuf->push_back(peek());
|
||||
}
|
||||
lexerState->captureSize++;
|
||||
++lexerState->captureSize;
|
||||
}
|
||||
|
||||
lexerState->macroArgScanDistance--;
|
||||
--lexerState->macroArgScanDistance;
|
||||
|
||||
for (;;) {
|
||||
if (!lexerState->expansions.empty()) {
|
||||
@@ -871,7 +870,7 @@ static void shiftChar() {
|
||||
} else {
|
||||
// Advance within the file contents
|
||||
if (std::holds_alternative<ViewedContent>(lexerState->content)) {
|
||||
std::get<ViewedContent>(lexerState->content).offset++;
|
||||
++std::get<ViewedContent>(lexerState->content).offset;
|
||||
} else {
|
||||
std::get<BufferedContent>(lexerState->content).advance();
|
||||
}
|
||||
@@ -1008,7 +1007,7 @@ static std::string readAnonLabelRef(char c) {
|
||||
// We come here having already peeked at one char, so no need to do it again
|
||||
do {
|
||||
shiftChar();
|
||||
n++;
|
||||
++n;
|
||||
} while (peek() == c);
|
||||
|
||||
return sym_MakeAnonLabelName(n, c == '-');
|
||||
@@ -1273,7 +1272,7 @@ static uint32_t readGfxConstant() {
|
||||
bitPlaneUpper = bitPlaneUpper << 1 | (pixel >> 1);
|
||||
}
|
||||
if (width < 9) {
|
||||
width++;
|
||||
++width;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2124,13 +2123,13 @@ static Token yylex_RAW() {
|
||||
|
||||
case '(': // Open parentheses inside macro args
|
||||
if (parenDepth < UINT_MAX) {
|
||||
parenDepth++;
|
||||
++parenDepth;
|
||||
}
|
||||
goto append;
|
||||
|
||||
case ')': // Close parentheses inside macro args
|
||||
if (parenDepth > 0) {
|
||||
parenDepth--;
|
||||
--parenDepth;
|
||||
}
|
||||
goto append;
|
||||
|
||||
@@ -2358,11 +2357,11 @@ static Token yylex_SKIP_TO_ENDR() {
|
||||
switch (readIdentifier(c, false).type) {
|
||||
case T_(POP_FOR):
|
||||
case T_(POP_REPT):
|
||||
depth++;
|
||||
++depth;
|
||||
break;
|
||||
|
||||
case T_(POP_ENDR):
|
||||
depth--;
|
||||
--depth;
|
||||
// `lexer_CaptureRept` has already guaranteed that the `ENDR`s are balanced
|
||||
assume(depth > 0);
|
||||
break;
|
||||
@@ -2483,12 +2482,12 @@ Capture lexer_CaptureRept() {
|
||||
switch (readIdentifier(c, false).type) {
|
||||
case T_(POP_REPT):
|
||||
case T_(POP_FOR):
|
||||
depth++;
|
||||
++depth;
|
||||
break; // Ignore the rest of that line
|
||||
|
||||
case T_(POP_ENDR):
|
||||
if (depth) {
|
||||
depth--;
|
||||
--depth;
|
||||
break; // Ignore the rest of that line
|
||||
}
|
||||
endCapture(capture);
|
||||
|
||||
@@ -293,7 +293,7 @@ int main(int argc, char *argv[]) {
|
||||
case 'Q':
|
||||
precisionArg = musl_optarg;
|
||||
if (precisionArg[0] == '.') {
|
||||
precisionArg++;
|
||||
++precisionArg;
|
||||
}
|
||||
precision = strtoul(precisionArg, &endptr, 0);
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ void opt_Parse(char const *s) {
|
||||
case 'Q':
|
||||
precisionArg = &s[1];
|
||||
if (precisionArg[0] == '.') {
|
||||
precisionArg++;
|
||||
++precisionArg;
|
||||
}
|
||||
if (strlen(precisionArg) <= 2) {
|
||||
int result;
|
||||
|
||||
@@ -2830,7 +2830,7 @@ static size_t strlenUTF8(std::string const &str, bool printErrors) {
|
||||
state = UTF8_ACCEPT;
|
||||
// fallthrough
|
||||
case UTF8_ACCEPT:
|
||||
len++;
|
||||
++len;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2840,7 +2840,7 @@ static size_t strlenUTF8(std::string const &str, bool printErrors) {
|
||||
if (printErrors) {
|
||||
error("STRLEN: Incomplete UTF-8 character");
|
||||
}
|
||||
len++;
|
||||
++len;
|
||||
}
|
||||
|
||||
return len;
|
||||
@@ -2861,10 +2861,10 @@ static std::string strsliceUTF8(std::string const &str, uint32_t start, uint32_t
|
||||
state = UTF8_ACCEPT;
|
||||
// fallthrough
|
||||
case UTF8_ACCEPT:
|
||||
curIdx++;
|
||||
++curIdx;
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
++index;
|
||||
}
|
||||
|
||||
// An index 1 past the end of the string is allowed, but will trigger the
|
||||
@@ -2887,16 +2887,16 @@ static std::string strsliceUTF8(std::string const &str, uint32_t start, uint32_t
|
||||
state = UTF8_ACCEPT;
|
||||
// fallthrough
|
||||
case UTF8_ACCEPT:
|
||||
curIdx++;
|
||||
++curIdx;
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
++index;
|
||||
}
|
||||
|
||||
// Check for partial code point.
|
||||
if (state != UTF8_ACCEPT) {
|
||||
error("STRSLICE: Incomplete UTF-8 character");
|
||||
curIdx++;
|
||||
++curIdx;
|
||||
}
|
||||
|
||||
if (curIdx < stop) {
|
||||
@@ -2925,10 +2925,10 @@ static std::string strsubUTF8(std::string const &str, uint32_t pos, uint32_t len
|
||||
state = UTF8_ACCEPT;
|
||||
// fallthrough
|
||||
case UTF8_ACCEPT:
|
||||
curPos++;
|
||||
++curPos;
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
++index;
|
||||
}
|
||||
|
||||
// A position 1 past the end of the string is allowed, but will trigger the
|
||||
@@ -2950,16 +2950,16 @@ static std::string strsubUTF8(std::string const &str, uint32_t pos, uint32_t len
|
||||
state = UTF8_ACCEPT;
|
||||
// fallthrough
|
||||
case UTF8_ACCEPT:
|
||||
curLen++;
|
||||
++curLen;
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
++index;
|
||||
}
|
||||
|
||||
// Check for partial code point.
|
||||
if (state != UTF8_ACCEPT) {
|
||||
error("STRSUB: Incomplete UTF-8 character");
|
||||
curLen++;
|
||||
++curLen;
|
||||
}
|
||||
|
||||
if (curLen < len) {
|
||||
@@ -3147,7 +3147,7 @@ static std::string
|
||||
fmt.appendString(str, std::get<std::string>(args[argIndex]));
|
||||
}
|
||||
|
||||
argIndex++;
|
||||
++argIndex;
|
||||
}
|
||||
|
||||
if (argIndex < args.size()) {
|
||||
|
||||
@@ -98,7 +98,7 @@ Section *sect_FindSectionByName(std::string const &name) {
|
||||
#define sectError(...) \
|
||||
do { \
|
||||
error(__VA_ARGS__); \
|
||||
nbSectErrors++; \
|
||||
++nbSectErrors; \
|
||||
} while (0)
|
||||
|
||||
static unsigned int mergeSectUnion(
|
||||
|
||||
@@ -545,7 +545,7 @@ Symbol *sym_AddAnonLabel() {
|
||||
}
|
||||
|
||||
std::string anon = sym_MakeAnonLabelName(0, true); // The direction is important!
|
||||
anonLabelID++;
|
||||
++anonLabelID;
|
||||
return addLabel(anon);
|
||||
}
|
||||
|
||||
@@ -565,8 +565,8 @@ std::string sym_MakeAnonLabelName(uint32_t ofs, bool neg) {
|
||||
id = anonLabelID - ofs;
|
||||
}
|
||||
} else {
|
||||
ofs--; // We're referencing symbols that haven't been created yet...
|
||||
if (ofs > UINT32_MAX - anonLabelID) {
|
||||
// We're referencing symbols that haven't been created yet...
|
||||
if (--ofs > UINT32_MAX - anonLabelID) {
|
||||
// LCOV_EXCL_START
|
||||
error(
|
||||
"Reference to anonymous label %" PRIu32 " after, when only %" PRIu32
|
||||
|
||||
@@ -81,8 +81,7 @@ static void printDiag(
|
||||
|
||||
static void incrementErrors() {
|
||||
// This intentionally makes 0 act as "unlimited" (or at least "limited to sizeof(unsigned)")
|
||||
nbErrors++;
|
||||
if (nbErrors == maxErrors) {
|
||||
if (++nbErrors == maxErrors) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"Assembly aborted after the maximum of %u error%s! (configure with "
|
||||
|
||||
Reference in New Issue
Block a user