scanner: preallocate space for tokens to reduce the number of allocations in the hot loop

pull/12298/head
Delyan Angelov 2021-10-28 16:23:17 +03:00
parent 5ecaa160a7
commit 99e71d0868
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 2 additions and 0 deletions

View File

@ -560,6 +560,8 @@ pub fn (mut s Scanner) scan_all_tokens_in_buffer(mode CommentsMode) {
} }
oldmode := s.comments_mode oldmode := s.comments_mode
s.comments_mode = mode s.comments_mode = mode
// preallocate space for tokens
s.all_tokens = []token.Token{cap: s.text.len / 3}
s.scan_remaining_text() s.scan_remaining_text()
s.comments_mode = oldmode s.comments_mode = oldmode
s.tidx = 0 s.tidx = 0