gbdev / rgbds

Rednex Game Boy Development System - An assembly toolchain for the Nintendo Game Boy and Game Boy Color
https://rgbds.gbdev.io
MIT License
1.35k stars 172 forks source link

Refactor to use an `if` instead of a `break` #967

Closed Rangi42 closed 2 years ago

Rangi42 commented 2 years ago

https://github.com/gbdev/rgbds/blob/master/src/asm/lexer.c#L50-L63 :

-    if (file == INVALID_HANDLE_VALUE) \
-        break; \
+    if (file != INVALID_HANDLE_VALUE) { \
     mappingObj  = CreateFileMappingA(file, NULL, PAGE_READONLY, 0, 0, NULL); \
     if (mappingObj != INVALID_HANDLE_VALUE) \
         (ptr) = MapViewOfFile(mappingObj, FILE_MAP_READ, 0, 0, 0); \
     CloseHandle(mappingObj); \
     CloseHandle(file); \
+    }
ISSOtm commented 2 years ago

I think the rationale was avoiding an extra indentation level, but this is OK as well.

ISSOtm commented 2 years ago

Yeah, it's breaking out of the enclosing do {} while (0); in the same way that we'd use a return; to exit from a failing function.