scanner: preallocate space for tokens to reduce the number of allocations in the hot loop
parent
5ecaa160a7
commit
99e71d0868
|
@ -560,6 +560,8 @@ pub fn (mut s Scanner) scan_all_tokens_in_buffer(mode CommentsMode) {
|
|||
}
|
||||
oldmode := s.comments_mode
|
||||
s.comments_mode = mode
|
||||
// preallocate space for tokens
|
||||
s.all_tokens = []token.Token{cap: s.text.len / 3}
|
||||
s.scan_remaining_text()
|
||||
s.comments_mode = oldmode
|
||||
s.tidx = 0
|
||||
|
|
Loading…
Reference in New Issue