-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fcin: make the fcgetc() macro less ugly
The fcgetc() macro of the Fcin interface (fast I/O library used by the lexer and parser) is written in an annoying and confusing way: #define fcgetc(c) (((c=fcget()) || (c=fcfill())), c) #define fcget() ((int)(*_Fcin.fcptr++)) ...where fcfill() is a function that reads more data from the input file after the buffer runs out. The fcgetc() macro modifies the variable passed to it, and also returns that variable's value. This is quite redundant, and makes the macro usage in the code misleading and confusing. It also requires a scratch variable to simply skip a character. To fix this awfulness, we don't need to go as far as ksh2020 did[*] and convert the macro to a library function, slightly impacting performance. Instead, we can rewrite it into a simple function-like macro that doesn't take any arguments: #define fcgetc() (*_Fcin.fcptr++ ? (int)_Fcin.fcptr[-1] : fcfill()) which means that, e.g., fcgetc(c) is now changed to c = fcgetc(), and we can eliminate variables where the stored value isn't used. [*] att@86f38e4c
- Loading branch information
Showing
4 changed files
with
50 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.