zig icon indicating copy to clipboard operation
zig copied to clipboard

std: add peek function to std.json.TokenStream

Open adarah opened this issue 2 years ago • 0 comments

First time contributing, hope this PR is up to your standards.

Similarly to #11925, this peek implementation technically does modify the internal i counter to speed up subsequent peek calls, but it shouldn't have any other impact. This is useful because next has been refactored to invoke peek internally, so the common case of invoking peek followed by next will still be fast. If this approach is not ok, then I can refactor peek so that subsequent calls repeat the same work.

One thing I'm very uncertain about is the change in the stackUsed method (only used in tests), particularly the contribution of token1/token2 to the stack size. My understanding is that the StreamingParser's stack is only used to keep track of opening/closing brackets, and token2 is only ever populated with the token immediately after a number, which implies "If token2 is not null, then token1 is a number". With that in mind, should we not validate if token1 and token2 are brackets/braces rather than just checking for not null?

Closes #12463.

adarah avatar Sep 09 '22 17:09 adarah