diff options
| author | 0x221e | 2026-06-16 02:23:21 +0200 |
|---|---|---|
| committer | 0x221e | 2026-06-16 15:53:47 +0200 |
| commit | e3cb7a6cab35947bb200f982f5fa8017b96bc15f (patch) | |
| tree | b8b57025e1e40873dddafe4be4b3c852eca52e45 | |
| parent | aab8263f58be6479cc73033a745459849fba7f0a (diff) | |
lex: remove redundant function calls from lex_number()
Redundant function calls removed from lex_number() by reducing
lex_seek() calls from 5 to 2. lex_seek already provides a safe
fallback for NULL values in the buffer, therefore removed the
redundant safety check as well.
| -rw-r--r-- | lex/lex.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -92,7 +92,7 @@ char lex_seek(struct lex *l, size_t o) assert(l != NULL); if (l->buffer[l->pos + o]) return l->buffer[l->pos + o]; - return '\0'; + return 0; } struct token lex_token_create(int tt, char* lexeme, size_t s) @@ -106,14 +106,17 @@ struct token lex_number(struct lex *l) int state = 0; - if (lex_seek(l, 0) == '0') { + char current_tkn = lex_seek(l, 0); + char next_tkn = lex_seek(l, 1); + + if (current_tkn == '0') { - if (lex_seek(l, 1) && lex_seek(l, 1) == 'x') { + if (next_tkn == 'x') { state = 1; l->pos += 2; } - if (lex_seek(l, 1) && lex_seek(l, 1) == 'b') { + if (next_tkn == 'b') { state = 2; l->pos += 2; } |
