Skip to content

Commit fd96154

Browse files
authored
Optimize lookAhead to avoid extra closures over Parser (microsoft#392)
1 parent 4e9d303 commit fd96154

File tree

2 files changed

+60
-58
lines changed

2 files changed

+60
-58
lines changed

internal/parser/jsdoc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func (p *Parser) isNextNonwhitespaceTokenEndOfFile() bool {
338338

339339
func (p *Parser) skipWhitespace() {
340340
if p.token == ast.KindWhitespaceTrivia || p.token == ast.KindNewLineTrivia {
341-
if p.lookAhead(p.isNextNonwhitespaceTokenEndOfFile) {
341+
if p.lookAhead((*Parser).isNextNonwhitespaceTokenEndOfFile) {
342342
return
343343
// Don't skip whitespace prior to EoF (or end of comment) - that shouldn't be included in any node's range
344344
}
@@ -350,7 +350,7 @@ func (p *Parser) skipWhitespace() {
350350

351351
func (p *Parser) skipWhitespaceOrAsterisk() string {
352352
if p.token == ast.KindWhitespaceTrivia || p.token == ast.KindNewLineTrivia {
353-
if p.lookAhead(p.isNextNonwhitespaceTokenEndOfFile) {
353+
if p.lookAhead((*Parser).isNextNonwhitespaceTokenEndOfFile) {
354354
return ""
355355
// Don't skip whitespace prior to EoF (or end of comment) - that shouldn't be included in any node's range
356356
}
@@ -725,7 +725,7 @@ func (p *Parser) parseParameterOrPropertyTag(start int, tagName *ast.IdentifierN
725725
name, isBracketed := p.parseBracketNameInPropertyAndParamTag()
726726
indentText := p.skipWhitespaceOrAsterisk()
727727

728-
if isNameFirst && p.lookAhead(func() bool { _, ok := p.parseJSDocLinkPrefix(); return !ok }) {
728+
if isNameFirst && p.lookAhead(func(p *Parser) bool { _, ok := p.parseJSDocLinkPrefix(); return !ok }) {
729729
typeExpression = p.tryParseTypeExpression()
730730
}
731731

@@ -802,7 +802,7 @@ func (p *Parser) parseTypeTag(previousTags []*ast.Node, start int, tagName *ast.
802802
}
803803

804804
func (p *Parser) parseSeeTag(start int, tagName *ast.IdentifierNode, indent int, indentText string) *ast.Node {
805-
isMarkdownOrJSDocLink := p.token == ast.KindOpenBracketToken || p.lookAhead(func() bool {
805+
isMarkdownOrJSDocLink := p.token == ast.KindOpenBracketToken || p.lookAhead(func(p *Parser) bool {
806806
return p.nextTokenJSDoc() == ast.KindAtToken && tokenIsIdentifierOrKeyword(p.nextTokenJSDoc()) && isJSDocLinkTag(p.scanner.TokenValue())
807807
})
808808
var nameExpression *ast.Node

0 commit comments

Comments
 (0)