Skip to content

Commit f3292d1

Browse files
committed
Add inbounds annotations in peek()
Some inbounds annotations in the `peek()` hot code paths seem to provide a few percent improvement (maybe 5%)?
1 parent fce6572 commit f3292d1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/parse_stream.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ end
325325
# unrolled optimized version for that fast path. Empirically it seems we
326326
# only hit the slow path about 5% of the time here.
327327
i = stream.lookahead_index
328-
if n == 1 && i+1 <= length(stream.lookahead)
328+
@inbounds if n == 1 && i+1 <= length(stream.lookahead)
329329
if skip_newlines
330330
k = kind(stream.lookahead[i])
331331
if !(k == K"Whitespace" || k == K"Comment" || k == K"NewlineWs")
@@ -364,7 +364,7 @@ end
364364
end
365365
_buffer_lookahead_tokens(stream.lexer, stream.lookahead)
366366
end
367-
k = kind(stream.lookahead[i])
367+
k = @inbounds kind(stream.lookahead[i])
368368
if !((k == K"Whitespace" || k == K"Comment") ||
369369
(k == K"NewlineWs" && skip_newlines))
370370
if n == 1
@@ -409,7 +409,7 @@ function peek_token(stream::ParseStream, n::Integer=1;
409409
if !skip_whitespace
410410
i = stream.lookahead_index
411411
end
412-
return stream.lookahead[i]
412+
return @inbounds stream.lookahead[i]
413413
end
414414

415415
function _peek_behind_fields(ranges, i)

0 commit comments

Comments
 (0)