Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: pkg/analyzer/lib/dart/ast/token.dart

Issue 1955373003: Convert some for-in loops for performance (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/dart/ast/ast.dart ('k') | pkg/analyzer/lib/src/dart/ast/ast.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Defines the tokens that are produced by the scanner, used by the parser, and 6 * Defines the tokens that are produced by the scanner, used by the parser, and
7 * referenced from the [AST structure](ast.dart). 7 * referenced from the [AST structure](ast.dart).
8 */ 8 */
9 library analyzer.dart.ast.token; 9 library analyzer.dart.ast.token;
10 10
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 /** 353 /**
354 * Compare the given [tokens] to find the token that appears first in the 354 * Compare the given [tokens] to find the token that appears first in the
355 * source being parsed. That is, return the left-most of all of the tokens. 355 * source being parsed. That is, return the left-most of all of the tokens.
356 * The list must be non-`null`, but the elements of the list are allowed to be 356 * The list must be non-`null`, but the elements of the list are allowed to be
357 * `null`. Return the token with the smallest offset, or `null` if the list is 357 * `null`. Return the token with the smallest offset, or `null` if the list is
358 * empty or if all of the elements of the list are `null`. 358 * empty or if all of the elements of the list are `null`.
359 */ 359 */
360 static Token lexicallyFirst(List<Token> tokens) { 360 static Token lexicallyFirst(List<Token> tokens) {
361 Token first = null; 361 Token first = null;
362 int offset = -1; 362 int offset = -1;
363 for (Token token in tokens) { 363 int length = tokens.length;
364 for (int i = 0; i < length; i++) {
365 Token token = tokens[i];
364 if (token != null && (offset < 0 || token.offset < offset)) { 366 if (token != null && (offset < 0 || token.offset < offset)) {
365 first = token; 367 first = token;
366 offset = token.offset; 368 offset = token.offset;
367 } 369 }
368 } 370 }
369 return first; 371 return first;
370 } 372 }
371 } 373 }
372 374
373 /** 375 /**
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 */ 736 */
735 class _EndOfFileTokenType extends TokenType { 737 class _EndOfFileTokenType extends TokenType {
736 /** 738 /**
737 * Initialize a newly created token. 739 * Initialize a newly created token.
738 */ 740 */
739 const _EndOfFileTokenType() : super._('EOF', TokenClass.NO_CLASS, ''); 741 const _EndOfFileTokenType() : super._('EOF', TokenClass.NO_CLASS, '');
740 742
741 @override 743 @override
742 String toString() => '-eof-'; 744 String toString() => '-eof-';
743 } 745 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/dart/ast/ast.dart ('k') | pkg/analyzer/lib/src/dart/ast/ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698