Skip to content

Commit 752b760

Browse files
jensjohaCommit Queue
authored andcommitted
[parser] notEofOrValue -> notEofOrType - skip string comparison
A small one. pkg/analyzer/lib/src/dart/ast/ast.dart: JIT (tokens per microsecond): 1.7597% +/- 1.4621% (0.37 +/- 0.30) (20.79 -> 21.15) AOT (tokens per microsecond): 2.2547% +/- 1.6761% (0.62 +/- 0.46) (27.67 -> 28.30) Benchmarker (AOT): ``` msec task-clock:u: -2.4779% +/- 1.3546% (-73.29 +/- 40.07) (2957.87 -> 2884.58) cycles:u: -2.6238% +/- 1.3918% (-337224094.10 +/- 178886541.74) (12852601263.80 -> 12515377169.70) instructions:u: -0.9484% +/- 0.0000% (-260552753.00 +/- 375.88) (27473305680.40 -> 27212752927.40) branch-misses:u: -8.7134% +/- 6.9328% (-3191115.20 +/- 2538992.37) (36623085.10 -> 33431969.90) seconds time elapsed: -2.4691% +/- 1.3512% (-0.07 +/- 0.04) (2.96 -> 2.89) seconds user: -2.4294% +/- 1.3675% (-0.07 +/- 0.04) (2.93 -> 2.86) ``` pkg/front_end/lib/src/type_inference/inference_visitor.dart: JIT (tokens per microsecond): No change. AOT (tokens per microsecond): No change. Benchmarker (AOT): ``` msec task-clock:u: -4.3099% +/- 1.9546% (-136.28 +/- 61.81) (3162.10 -> 3025.81) cycles:u: -4.3066% +/- 1.9530% (-592061704.80 +/- 268488936.68) (13747787475.20 -> 13155725770.40) instructions:u: -0.5194% +/- 0.0000% (-156988901.90 +/- 1876.14) (30225890142.20 -> 30068901240.30) branch-misses:u: -14.2999% +/- 7.5350% (-6167339.80 +/- 3249736.99) (43128654.50 -> 36961314.70) seconds time elapsed: -4.3098% +/- 1.9527% (-0.14 +/- 0.06) (3.16 -> 3.03) seconds user: -4.3252% +/- 1.9575% (-0.14 +/- 0.06) (3.14 -> 3.01) ``` Change-Id: Ib70398e337c482f7427debb6875e2c17ccc6bd0f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439740 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 06402ab commit 752b760

File tree

804 files changed

+6098
-6097
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

804 files changed

+6098
-6097
lines changed

pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,7 +2592,7 @@ class Parser {
25922592
}
25932593
listener.handleEnumElements(token, elementCount);
25942594
if (token.isA(TokenType.SEMICOLON)) {
2595-
while (notEofOrValue('}', token.next!)) {
2595+
while (notEofOrType(TokenType.CLOSE_CURLY_BRACKET, token.next!)) {
25962596
token = parseClassOrMixinOrExtensionOrEnumMemberImpl(
25972597
token,
25982598
DeclarationKind.Enum,
@@ -3748,8 +3748,8 @@ class Parser {
37483748
return identifier;
37493749
}
37503750

3751-
bool notEofOrValue(String value, Token token) {
3752-
return token.kind != EOF_TOKEN && value != token.stringValue;
3751+
bool notEofOrType(TokenType type, Token token) {
3752+
return !token.isA(TokenType.EOF) && !token.isA(type);
37533753
}
37543754

37553755
Token parseTypeVariablesOpt(Token token) {
@@ -4849,7 +4849,7 @@ class Parser {
48494849
assert(token.isA(TokenType.OPEN_CURLY_BRACKET));
48504850
listener.beginClassOrMixinOrExtensionBody(kind, token);
48514851
int count = 0;
4852-
while (notEofOrValue('}', token.next!)) {
4852+
while (notEofOrType(TokenType.CLOSE_CURLY_BRACKET, token.next!)) {
48534853
token = parseClassOrMixinOrExtensionOrEnumMemberImpl(
48544854
token,
48554855
kind,
@@ -6142,7 +6142,7 @@ class Parser {
61426142
loopState = LoopState.OutsideLoop;
61436143
listener.beginBlockFunctionBody(begin);
61446144
token = next;
6145-
while (notEofOrValue('}', token.next!)) {
6145+
while (notEofOrType(TokenType.CLOSE_CURLY_BRACKET, token.next!)) {
61466146
Token startToken = token.next!;
61476147
token = parseStatement(token);
61486148
if (identical(token.next!, startToken)) {
@@ -9856,7 +9856,7 @@ class Parser {
98569856
listener.beginBlock(begin, blockKind);
98579857
int statementCount = 0;
98589858
Token startToken = token.next!;
9859-
while (notEofOrValue('}', startToken)) {
9859+
while (notEofOrType(TokenType.CLOSE_CURLY_BRACKET, startToken)) {
98609860
token = parseStatement(token);
98619861
if (identical(token.next!, startToken)) {
98629862
// No progress was made, so we report the current token as being invalid
@@ -10247,7 +10247,7 @@ class Parser {
1024710247
int caseCount = 0;
1024810248
Token? defaultKeyword = null;
1024910249
Token? colonAfterDefault = null;
10250-
while (notEofOrValue('}', token.next!)) {
10250+
while (notEofOrType(TokenType.CLOSE_CURLY_BRACKET, token.next!)) {
1025110251
Token beginCase = token.next!;
1025210252
int expressionCount = 0;
1025310253
int labelCount = 0;
@@ -10733,7 +10733,7 @@ class Parser {
1073310733
next = rewriter.insertSyntheticToken(token, TokenType.SEMICOLON);
1073410734
listener.handleEmptyStatement(next);
1073510735

10736-
while (notEofOrValue('}', next)) {
10736+
while (notEofOrType(TokenType.CLOSE_CURLY_BRACKET, next)) {
1073710737
token = next;
1073810738
next = token.next!;
1073910739
}

pkg/_fe_analyzer_shared/test/parser_benchmark.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void main(List<String> args) {
7474
if (listener is NullListener && listener.hasErrors) {
7575
numErrors++;
7676
}
77+
// Or maybe - maybe as an option - do another scan here?
7778
}
7879

7980
stopwatch.stop();

pkg/front_end/parser_testcases/also-nnbd/issue_39326.dart.intertwined.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ parseUnit(main)
2626
inPlainSync()
2727
parseFunctionBody(), false, false)
2828
listener: beginBlockFunctionBody({)
29-
notEofOrValue(}, var)
29+
notEofOrType(CLOSE_CURLY_BRACKET, var)
3030
parseStatement({)
3131
parseStatementX({)
3232
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, null)
@@ -45,7 +45,7 @@ parseUnit(main)
4545
listener: endInitializedIdentifier(c)
4646
ensureSemicolon(c)
4747
listener: endVariablesDeclaration(1, ;)
48-
notEofOrValue(}, c)
48+
notEofOrType(CLOSE_CURLY_BRACKET, c)
4949
parseStatement(;)
5050
parseStatementX(;)
5151
parseExpressionStatementOrDeclarationAfterModifiers(;, ;, null, null, null, null)
@@ -83,7 +83,7 @@ parseUnit(main)
8383
listener: handleAssignmentExpression(=, 42)
8484
ensureSemicolon(42)
8585
listener: handleExpressionStatement(c, ;)
86-
notEofOrValue(}, })
86+
notEofOrType(CLOSE_CURLY_BRACKET, })
8787
listener: endBlockFunctionBody(2, {, })
8888
listener: endTopLevelMethod(main, null, })
8989
listener: endTopLevelDeclaration(})

pkg/front_end/parser_testcases/also-nnbd/issue_40267_conditional.dart.intertwined.expect

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ parseUnit(f)
2626
inPlainSync()
2727
parseFunctionBody(), false, false)
2828
listener: beginBlockFunctionBody({)
29-
notEofOrValue(}, var)
29+
notEofOrType(CLOSE_CURLY_BRACKET, var)
3030
parseStatement({)
3131
parseStatementX({)
3232
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, null)
@@ -59,7 +59,7 @@ parseUnit(f)
5959
listener: endInitializedIdentifier(c)
6060
ensureSemicolon(c)
6161
listener: endVariablesDeclaration(3, ;)
62-
notEofOrValue(}, a)
62+
notEofOrType(CLOSE_CURLY_BRACKET, a)
6363
parseStatement(;)
6464
parseStatementX(;)
6565
parseExpressionStatementOrDeclarationAfterModifiers(;, ;, null, null, null, null)
@@ -142,7 +142,7 @@ parseUnit(f)
142142
listener: endConditionalExpression(?, :, c)
143143
ensureSemicolon(c)
144144
listener: handleExpressionStatement(a, ;)
145-
notEofOrValue(}, a)
145+
notEofOrType(CLOSE_CURLY_BRACKET, a)
146146
parseStatement(;)
147147
parseStatementX(;)
148148
parseExpressionStatementOrDeclarationAfterModifiers(;, ;, null, null, null, null)
@@ -225,7 +225,7 @@ parseUnit(f)
225225
listener: endConditionalExpression(?, :, c)
226226
ensureSemicolon(c)
227227
listener: handleExpressionStatement(a, ;)
228-
notEofOrValue(}, a)
228+
notEofOrType(CLOSE_CURLY_BRACKET, a)
229229
parseStatement(;)
230230
parseStatementX(;)
231231
parseExpressionStatementOrDeclarationAfterModifiers(;, ;, null, null, null, null)
@@ -330,7 +330,7 @@ parseUnit(f)
330330
listener: endConditionalExpression(?, :, c)
331331
ensureSemicolon(c)
332332
listener: handleExpressionStatement(a, ;)
333-
notEofOrValue(}, a)
333+
notEofOrType(CLOSE_CURLY_BRACKET, a)
334334
parseStatement(;)
335335
parseStatementX(;)
336336
parseExpressionStatementOrDeclarationAfterModifiers(;, ;, null, null, null, null)
@@ -435,7 +435,7 @@ parseUnit(f)
435435
listener: endConditionalExpression(?, :, c)
436436
ensureSemicolon(c)
437437
listener: handleExpressionStatement(a, ;)
438-
notEofOrValue(}, a)
438+
notEofOrType(CLOSE_CURLY_BRACKET, a)
439439
parseStatement(;)
440440
parseStatementX(;)
441441
parseExpressionStatementOrDeclarationAfterModifiers(;, ;, null, null, null, null)
@@ -511,7 +511,7 @@ parseUnit(f)
511511
listener: endConditionalExpression(?, :, ])
512512
ensureSemicolon(])
513513
listener: handleExpressionStatement(a, ;)
514-
notEofOrValue(}, a)
514+
notEofOrType(CLOSE_CURLY_BRACKET, a)
515515
parseStatement(;)
516516
parseStatementX(;)
517517
parseExpressionStatementOrDeclarationAfterModifiers(;, ;, null, null, null, null)
@@ -595,7 +595,7 @@ parseUnit(f)
595595
listener: endConditionalExpression(?, :, ))
596596
ensureSemicolon())
597597
listener: handleExpressionStatement(a, ;)
598-
notEofOrValue(}, })
598+
notEofOrType(CLOSE_CURLY_BRACKET, })
599599
listener: endBlockFunctionBody(7, {, })
600600
listener: endTopLevelMethod(f, null, })
601601
listener: endTopLevelDeclaration(})

pkg/front_end/parser_testcases/also-nnbd/issue_40267_conditional_2.dart.intertwined.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ parseUnit(f)
2626
inPlainSync()
2727
parseFunctionBody(), false, false)
2828
listener: beginBlockFunctionBody({)
29-
notEofOrValue(}, var)
29+
notEofOrType(CLOSE_CURLY_BRACKET, var)
3030
parseStatement({)
3131
parseStatementX({)
3232
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, null)
@@ -52,7 +52,7 @@ parseUnit(f)
5252
listener: endInitializedIdentifier(b)
5353
ensureSemicolon(b)
5454
listener: endVariablesDeclaration(2, ;)
55-
notEofOrValue(}, return)
55+
notEofOrType(CLOSE_CURLY_BRACKET, return)
5656
parseStatement(;)
5757
parseStatementX(;)
5858
parseReturnStatement(;)
@@ -149,7 +149,7 @@ parseUnit(f)
149149
ensureSemicolon(null)
150150
listener: endReturnStatement(true, return, ;)
151151
inGenerator()
152-
notEofOrValue(}, })
152+
notEofOrType(CLOSE_CURLY_BRACKET, })
153153
listener: endBlockFunctionBody(2, {, })
154154
listener: endTopLevelMethod(f, null, })
155155
listener: endTopLevelDeclaration(})

pkg/front_end/parser_testcases/also-nnbd/issue_40267_conditional_3.dart.intertwined.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ parseUnit(f)
2626
inPlainSync()
2727
parseFunctionBody(), false, false)
2828
listener: beginBlockFunctionBody({)
29-
notEofOrValue(}, var)
29+
notEofOrType(CLOSE_CURLY_BRACKET, var)
3030
parseStatement({)
3131
parseStatementX({)
3232
parseExpressionStatementOrDeclarationAfterModifiers(var, {, null, var, null, null)
@@ -45,7 +45,7 @@ parseUnit(f)
4545
listener: endInitializedIdentifier(a)
4646
ensureSemicolon(a)
4747
listener: endVariablesDeclaration(1, ;)
48-
notEofOrValue(}, return)
48+
notEofOrType(CLOSE_CURLY_BRACKET, return)
4949
parseStatement(;)
5050
parseStatementX(;)
5151
parseReturnStatement(;)
@@ -159,7 +159,7 @@ parseUnit(f)
159159
ensureSemicolon(])
160160
listener: endReturnStatement(true, return, ;)
161161
inGenerator()
162-
notEofOrValue(}, })
162+
notEofOrType(CLOSE_CURLY_BRACKET, })
163163
listener: endBlockFunctionBody(2, {, })
164164
listener: endTopLevelMethod(f, null, })
165165
listener: endTopLevelDeclaration(})

pkg/front_end/parser_testcases/also-nnbd/issue_40288.dart.intertwined.expect

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ parseUnit(class)
2727
listener: handleClassHeader(class, class, null)
2828
parseClassOrMixinOrExtensionBody(late, DeclarationKind.Class, late)
2929
listener: beginClassOrMixinOrExtensionBody(DeclarationKind.Class, {)
30-
notEofOrValue(}, int)
30+
notEofOrType(CLOSE_CURLY_BRACKET, int)
3131
parseClassOrMixinOrExtensionOrEnumMemberImpl({, DeclarationKind.Class, late)
3232
parseMetadataStar({)
3333
listener: beginMetadataStar(int)
@@ -64,7 +64,7 @@ parseUnit(class)
6464
inGenerator()
6565
listener: endClassMethod(get, int, =>, null, ;)
6666
listener: endMember()
67-
notEofOrValue(}, })
67+
notEofOrType(CLOSE_CURLY_BRACKET, })
6868
listener: endClassOrMixinOrExtensionBody(DeclarationKind.Class, 1, {, })
6969
listener: endClassDeclaration(class, })
7070
listener: endTopLevelDeclaration(})
@@ -93,7 +93,7 @@ parseUnit(class)
9393
listener: handleClassHeader(class, class, null)
9494
parseClassOrMixinOrExtensionBody(required, DeclarationKind.Class, required)
9595
listener: beginClassOrMixinOrExtensionBody(DeclarationKind.Class, {)
96-
notEofOrValue(}, int)
96+
notEofOrType(CLOSE_CURLY_BRACKET, int)
9797
parseClassOrMixinOrExtensionOrEnumMemberImpl({, DeclarationKind.Class, required)
9898
parseMetadataStar({)
9999
listener: beginMetadataStar(int)
@@ -130,7 +130,7 @@ parseUnit(class)
130130
inGenerator()
131131
listener: endClassMethod(get, int, =>, null, ;)
132132
listener: endMember()
133-
notEofOrValue(}, })
133+
notEofOrType(CLOSE_CURLY_BRACKET, })
134134
listener: endClassOrMixinOrExtensionBody(DeclarationKind.Class, 1, {, })
135135
listener: endClassDeclaration(class, })
136136
listener: endTopLevelDeclaration(})
@@ -157,7 +157,7 @@ parseUnit(class)
157157
listener: handleClassHeader(class, class, null)
158158
parseClassOrMixinOrExtensionBody(C, DeclarationKind.Class, C)
159159
listener: beginClassOrMixinOrExtensionBody(DeclarationKind.Class, {)
160-
notEofOrValue(}, late)
160+
notEofOrType(CLOSE_CURLY_BRACKET, late)
161161
parseClassOrMixinOrExtensionOrEnumMemberImpl({, DeclarationKind.Class, C)
162162
parseMetadataStar({)
163163
listener: beginMetadataStar(late)
@@ -195,7 +195,7 @@ parseUnit(class)
195195
listener: endFieldInitializer(=, ))
196196
listener: endClassFields(null, null, null, null, null, late, null, 1, late, ;)
197197
listener: endMember()
198-
notEofOrValue(}, required)
198+
notEofOrType(CLOSE_CURLY_BRACKET, required)
199199
parseClassOrMixinOrExtensionOrEnumMemberImpl(;, DeclarationKind.Class, C)
200200
parseMetadataStar(;)
201201
listener: beginMetadataStar(required)
@@ -235,7 +235,7 @@ parseUnit(class)
235235
listener: endFieldInitializer(=, ))
236236
listener: endClassFields(null, null, null, null, null, null, null, 1, required, ;)
237237
listener: endMember()
238-
notEofOrValue(}, })
238+
notEofOrType(CLOSE_CURLY_BRACKET, })
239239
listener: endClassOrMixinOrExtensionBody(DeclarationKind.Class, 2, {, })
240240
listener: endClassDeclaration(class, })
241241
listener: endTopLevelDeclaration(})

pkg/front_end/parser_testcases/also-nnbd/issue_40288_prime.dart.intertwined.expect

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ parseUnit(class)
2525
listener: handleClassHeader(class, class, null)
2626
parseClassOrMixinOrExtensionBody(Xlate, DeclarationKind.Class, Xlate)
2727
listener: beginClassOrMixinOrExtensionBody(DeclarationKind.Class, {)
28-
notEofOrValue(}, int)
28+
notEofOrType(CLOSE_CURLY_BRACKET, int)
2929
parseClassOrMixinOrExtensionOrEnumMemberImpl({, DeclarationKind.Class, Xlate)
3030
parseMetadataStar({)
3131
listener: beginMetadataStar(int)
@@ -62,7 +62,7 @@ parseUnit(class)
6262
inGenerator()
6363
listener: endClassMethod(get, int, =>, null, ;)
6464
listener: endMember()
65-
notEofOrValue(}, })
65+
notEofOrType(CLOSE_CURLY_BRACKET, })
6666
listener: endClassOrMixinOrExtensionBody(DeclarationKind.Class, 1, {, })
6767
listener: endClassDeclaration(class, })
6868
listener: endTopLevelDeclaration(})
@@ -89,7 +89,7 @@ parseUnit(class)
8989
listener: handleClassHeader(class, class, null)
9090
parseClassOrMixinOrExtensionBody(Xrequired, DeclarationKind.Class, Xrequired)
9191
listener: beginClassOrMixinOrExtensionBody(DeclarationKind.Class, {)
92-
notEofOrValue(}, int)
92+
notEofOrType(CLOSE_CURLY_BRACKET, int)
9393
parseClassOrMixinOrExtensionOrEnumMemberImpl({, DeclarationKind.Class, Xrequired)
9494
parseMetadataStar({)
9595
listener: beginMetadataStar(int)
@@ -126,7 +126,7 @@ parseUnit(class)
126126
inGenerator()
127127
listener: endClassMethod(get, int, =>, null, ;)
128128
listener: endMember()
129-
notEofOrValue(}, })
129+
notEofOrType(CLOSE_CURLY_BRACKET, })
130130
listener: endClassOrMixinOrExtensionBody(DeclarationKind.Class, 1, {, })
131131
listener: endClassDeclaration(class, })
132132
listener: endTopLevelDeclaration(})
@@ -153,7 +153,7 @@ parseUnit(class)
153153
listener: handleClassHeader(class, class, null)
154154
parseClassOrMixinOrExtensionBody(C, DeclarationKind.Class, C)
155155
listener: beginClassOrMixinOrExtensionBody(DeclarationKind.Class, {)
156-
notEofOrValue(}, Xlate)
156+
notEofOrType(CLOSE_CURLY_BRACKET, Xlate)
157157
parseClassOrMixinOrExtensionOrEnumMemberImpl({, DeclarationKind.Class, C)
158158
parseMetadataStar({)
159159
listener: beginMetadataStar(Xlate)
@@ -188,7 +188,7 @@ parseUnit(class)
188188
listener: endFieldInitializer(=, ))
189189
listener: endClassFields(null, null, null, null, null, null, null, 1, Xlate, ;)
190190
listener: endMember()
191-
notEofOrValue(}, Xrequired)
191+
notEofOrType(CLOSE_CURLY_BRACKET, Xrequired)
192192
parseClassOrMixinOrExtensionOrEnumMemberImpl(;, DeclarationKind.Class, C)
193193
parseMetadataStar(;)
194194
listener: beginMetadataStar(Xrequired)
@@ -223,7 +223,7 @@ parseUnit(class)
223223
listener: endFieldInitializer(=, ))
224224
listener: endClassFields(null, null, null, null, null, null, null, 1, Xrequired, ;)
225225
listener: endMember()
226-
notEofOrValue(}, })
226+
notEofOrType(CLOSE_CURLY_BRACKET, })
227227
listener: endClassOrMixinOrExtensionBody(DeclarationKind.Class, 2, {, })
228228
listener: endClassDeclaration(class, })
229229
listener: endTopLevelDeclaration(})

pkg/front_end/parser_testcases/also-nnbd/nullable_type_argument.dart.intertwined.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ parseUnit(class)
3333
listener: handleClassHeader(class, class, null)
3434
parseClassOrMixinOrExtensionBody(>, DeclarationKind.Class, A)
3535
listener: beginClassOrMixinOrExtensionBody(DeclarationKind.Class, {)
36-
notEofOrValue(}, })
36+
notEofOrType(CLOSE_CURLY_BRACKET, })
3737
listener: endClassOrMixinOrExtensionBody(DeclarationKind.Class, 0, {, })
3838
listener: endClassDeclaration(class, })
3939
listener: endTopLevelDeclaration(})
@@ -68,7 +68,7 @@ parseUnit(class)
6868
listener: handleClassHeader(class, class, null)
6969
parseClassOrMixinOrExtensionBody(>, DeclarationKind.Class, B)
7070
listener: beginClassOrMixinOrExtensionBody(DeclarationKind.Class, {)
71-
notEofOrValue(}, })
71+
notEofOrType(CLOSE_CURLY_BRACKET, })
7272
listener: endClassOrMixinOrExtensionBody(DeclarationKind.Class, 0, {, })
7373
listener: endClassDeclaration(class, })
7474
listener: endTopLevelDeclaration(})

0 commit comments

Comments
 (0)