Skip to content

Commit c891014

Browse files
committed
scanner: reduce memory, increase speed for long commented sections
1 parent 022cc72 commit c891014

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

vlib/v/scanner/scanner.v

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub fn (mut s Scanner) set_current_tidx(cidx int) {
143143
s.tidx = tidx
144144
}
145145

146+
[inline]
146147
fn (mut s Scanner) new_token(tok_kind token.Kind, lit string, len int) token.Token {
147148
cidx := s.tidx
148149
s.tidx++
@@ -156,6 +157,7 @@ fn (mut s Scanner) new_token(tok_kind token.Kind, lit string, len int) token.Tok
156157
}
157158
}
158159

160+
[inline]
159161
fn (mut s Scanner) ident_name() string {
160162
start := s.pos
161163
s.pos++
@@ -531,6 +533,7 @@ fn (mut s Scanner) ident_number() string {
531533
}
532534
}
533535

536+
[inline]
534537
fn (mut s Scanner) skip_whitespace() {
535538
// if s.is_vh { println('vh') return }
536539
for s.pos < s.text.len && s.text[s.pos].is_space() {
@@ -1046,13 +1049,13 @@ fn (mut s Scanner) text_scan() token.Token {
10461049
if nextc == `/` {
10471050
start := s.pos + 1
10481051
s.ignore_line()
1049-
s.line_comment = s.text[start + 1..s.pos]
1050-
mut comment := s.line_comment.trim_space()
1052+
comment_line_end := s.pos
10511053
s.pos--
1052-
// fix line_nr, \n was read, and the comment is marked
1053-
// on the next line
1054+
// fix line_nr, \n was read; the comment is marked on the next line
10541055
s.line_nr--
10551056
if s.should_parse_comment() {
1057+
s.line_comment = s.text[start + 1..comment_line_end]
1058+
mut comment := s.line_comment.trim_space()
10561059
// Find out if this comment is on its own line (for vfmt)
10571060
mut is_separate_line_comment := true
10581061
for j := start - 2; j >= 0 && s.text[j] != `\n`; j-- {
@@ -1267,6 +1270,7 @@ fn (mut s Scanner) ident_char() string {
12671270
}
12681271
}
12691272

1273+
[inline]
12701274
fn (s &Scanner) expect(want string, start_pos int) bool {
12711275
end_pos := start_pos + want.len
12721276
if start_pos < 0 || start_pos >= s.text.len {
@@ -1306,17 +1310,20 @@ fn (mut s Scanner) debug_tokens() {
13061310
}
13071311
}
13081312

1313+
[inline]
13091314
fn (mut s Scanner) ignore_line() {
13101315
s.eat_to_end_of_line()
13111316
s.inc_line_number()
13121317
}
13131318

1319+
[inline]
13141320
fn (mut s Scanner) eat_to_end_of_line() {
13151321
for s.pos < s.text.len && s.text[s.pos] != `\n` {
13161322
s.pos++
13171323
}
13181324
}
13191325

1326+
[inline]
13201327
fn (mut s Scanner) inc_line_number() {
13211328
s.last_nl_pos = s.pos
13221329
s.line_nr++

0 commit comments

Comments
 (0)