v.scanner: apply `[direct_array_access]` for key frequently called low level functions

pull/10020/head
Delyan Angelov 2021-05-05 23:45:23 +03:00
parent ab39011fb9
commit 3405f517a4
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 10 additions and 5 deletions

View File

@ -215,11 +215,15 @@ fn (mut s Scanner) new_multiline_token(tok_kind token.Kind, lit string, len int,
} }
} }
[inline] [direct_array_access; inline]
fn (mut s Scanner) ident_name() string { fn (mut s Scanner) ident_name() string {
start := s.pos start := s.pos
s.pos++ s.pos++
for s.pos < s.text.len && (util.is_name_char(s.text[s.pos]) || s.text[s.pos].is_digit()) { for s.pos < s.text.len {
c := s.text[s.pos]
if !(util.is_name_char(c) || c.is_digit()) {
break
}
s.pos++ s.pos++
} }
name := s.text[start..s.pos] name := s.text[start..s.pos]
@ -498,7 +502,7 @@ fn (mut s Scanner) ident_number() string {
fn (mut s Scanner) skip_whitespace() { fn (mut s Scanner) skip_whitespace() {
for s.pos < s.text.len { for s.pos < s.text.len {
c := s.text[s.pos] c := s.text[s.pos]
if !c.is_space() { if !(c == 32 || (c > 8 && c < 14) || (c == 0x85) || (c == 0xa0)) {
return return
} }
c_is_nl := c == scanner.b_cr || c == scanner.b_lf c_is_nl := c == scanner.b_cr || c == scanner.b_lf
@ -595,7 +599,7 @@ pub fn (s &Scanner) peek_token(n int) token.Token {
return t return t
} }
[inline] [direct_array_access; inline]
fn (s &Scanner) look_ahead(n int) byte { fn (s &Scanner) look_ahead(n int) byte {
if s.pos + n < s.text.len { if s.pos + n < s.text.len {
return s.text[s.pos + n] return s.text[s.pos + n]
@ -1082,6 +1086,7 @@ fn (s &Scanner) count_symbol_before(p int, sym byte) int {
return count return count
} }
[direct_array_access]
fn (mut s Scanner) ident_string() string { fn (mut s Scanner) ident_string() string {
q := s.text[s.pos] q := s.text[s.pos]
is_quote := q == scanner.single_quote || q == scanner.double_quote is_quote := q == scanner.single_quote || q == scanner.double_quote
@ -1274,7 +1279,7 @@ fn (mut s Scanner) ident_char() string {
return c return c
} }
[inline] [direct_array_access; inline]
fn (s &Scanner) expect(want string, start_pos int) bool { fn (s &Scanner) expect(want string, start_pos int) bool {
end_pos := start_pos + want.len end_pos := start_pos + want.len
if start_pos < 0 || end_pos < 0 || start_pos >= s.text.len || end_pos > s.text.len { if start_pos < 0 || end_pos < 0 || start_pos >= s.text.len || end_pos > s.text.len {