Skip to content

fix(base-io): stop excessive re-reads in LookaheadReader's single-char lookahead path - #100

Merged
deer merged 1 commit into
mainfrom
lookahead_fix
Jul 29, 2026
Merged

fix(base-io): stop excessive re-reads in LookaheadReader's single-char lookahead path#100
deer merged 1 commit into
mainfrom
lookahead_fix

Conversation

@deer

@deer deer commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

LookaheadReader.prepare() (the no-arg overload used by consume(), peek(), available(), and follows()) delegated to prepare(DEFAULT_LOOKAHEAD), requesting a full 4096-character lookahead even for single-character operations.

Because the internal buffer is sized to exactly DEFAULT_LOOKAHEAD by default, this made the "not enough room" shuffle condition (index + desired > buffer.length) true again immediately after consuming just one character, forcing a fresh underlying read() call on essentially every single consume(). The fix changes the no-arg prepare() to request a desired of 1 instead, so the refill only triggers when the buffer is actually empty; the top-up read still fills as much of the buffer as is available, so bulk consumption via consume(int) is unaffected.

@deer
deer merged commit dcd087a into main Jul 29, 2026
3 checks passed
@deer
deer deleted the lookahead_fix branch July 29, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant