File tree 1 file changed +15
-3
lines changed 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -610,12 +610,24 @@ func (lexer *lexer) wouldStartNumber() bool {
610
610
return false
611
611
}
612
612
613
+ // Note: This function is hot in profiles
613
614
func (lexer * lexer ) consumeName () string {
614
- // Common case: no escapes, identifier is a substring of the input
615
- for IsNameContinue (lexer .codePoint ) {
615
+ // Common case: no escapes, identifier is a substring of the input. Doing this
616
+ // in a tight loop that avoids UTF-8 decoding and that increments a single
617
+ // number instead of doing "step()" is noticeably faster. For example, doing
618
+ // this sped up end-to-end parsing and printing of a large CSS file from 97ms
619
+ // to 84ms (around 15% faster).
620
+ contents := lexer .source .Contents
621
+ if IsNameContinue (lexer .codePoint ) {
622
+ n := len (contents )
623
+ i := lexer .current
624
+ for i < n && IsNameContinue (rune (contents [i ])) {
625
+ i ++
626
+ }
627
+ lexer .current = i
616
628
lexer .step ()
617
629
}
618
- raw := lexer . source . Contents [lexer .Token .Range .Loc .Start :lexer .Token .Range .End ()]
630
+ raw := contents [lexer .Token .Range .Loc .Start :lexer .Token .Range .End ()]
619
631
if ! lexer .isValidEscape () {
620
632
return raw
621
633
}
You can’t perform that action at this time.
0 commit comments