Skip to content

Commit

Permalink
Use a smaller size for the lexer buffer
Browse files Browse the repository at this point in the history
Large sizes are more efficient when it's actually buffered,
but most of the time `mmap` is used instead, and the extra size
just slows down allocation of lexer states.
  • Loading branch information
Rangi42 committed May 18, 2024
1 parent 352551d commit 39e9315
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/asm/lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
#include <memory>
#include <optional>
#include <stdint.h>
#include <stdio.h> // BUFSIZ
#include <string>
#include <variant>
#include <vector>

#include "platform.hpp" // SSIZE_MAX

#define LEXER_BUF_SIZE BUFSIZ
// This value is a compromise between `LexerState` allocation performance when `mmap` works, and
// buffering performance when it doesn't/can't (e.g. when piping a file into RGBASM).
#define LEXER_BUF_SIZE 64
// The buffer needs to be large enough for the maximum `lexerState->peek()` lookahead distance
static_assert(LEXER_BUF_SIZE > 1, "Lexer buffer size is too small");
// This caps the size of buffer reads, and according to POSIX, passing more than SSIZE_MAX is UB
Expand Down
1 change: 1 addition & 0 deletions src/asm/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
Expand Down

0 comments on commit 39e9315

Please sign in to comment.