Skip to content

Commit 33ae58d

Browse files
Hit the table once for whitespace, then tight-loop.
1 parent 3bdfe84 commit 33ae58d

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/compiler/scanner.ts

+13-17
Original file line numberDiff line numberDiff line change
@@ -1997,19 +1997,6 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
19971997

19981998
const ch = codePointUnchecked(pos);
19991999

2000-
if (ch === CharacterCodes.tab || ch === CharacterCodes.space) {
2001-
if (skipTrivia) {
2002-
pos++;
2003-
continue;
2004-
}
2005-
else {
2006-
while (pos < end && isWhiteSpaceSingleLine(charCodeUnchecked(pos))) {
2007-
pos++;
2008-
}
2009-
return token = SyntaxKind.WhitespaceTrivia;
2010-
}
2011-
}
2012-
20132000
if (ch === CharacterCodes.lineFeed || ch === CharacterCodes.carriageReturn) {
20142001
tokenFlags |= TokenFlags.PrecedingLineBreak;
20152002
if (skipTrivia) {
@@ -2044,14 +2031,23 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
20442031
}
20452032

20462033
if (tokenCategory & TokenCategory.Whitespace) {
2034+
pos++;
2035+
// Tight loop here on consecutive whitespace to avoid a table lookup.
2036+
while (pos < end) {
2037+
const nextCh = charCodeUnchecked(pos);
2038+
// Check for the original character to hitting the slow path.
2039+
if (nextCh === ch || isWhiteSpaceSingleLine(nextCh)) {
2040+
pos++;
2041+
continue;
2042+
}
2043+
2044+
break;
2045+
}
2046+
20472047
if (skipTrivia) {
2048-
pos++;
20492048
continue;
20502049
}
20512050
else {
2052-
while (pos < end && isWhiteSpaceSingleLine(charCodeUnchecked(pos))) {
2053-
pos++;
2054-
}
20552051
return token = SyntaxKind.WhitespaceTrivia;
20562052
}
20572053
}

0 commit comments

Comments
 (0)