1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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

This commit is contained in:
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

View File

@ -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