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

Side by Side Diff: pkg/compiler/lib/src/tokens/token_map.dart

Issue 1859343004: dartfmt pkg/compiler (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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/compiler/lib/src/tokens/token.dart ('k') | pkg/compiler/lib/src/tracer.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library dart2js.tokens.token_map; 5 library dart2js.tokens.token_map;
6 6
7 import 'token.dart' show 7 import 'token.dart' show Token;
8 Token;
9 8
10 /** 9 /**
11 * Key class used in [TokenMap] in which the hash code for a token is based 10 * Key class used in [TokenMap] in which the hash code for a token is based
12 * on the [charOffset]. 11 * on the [charOffset].
13 */ 12 */
14 class TokenKey { 13 class TokenKey {
15 final Token token; 14 final Token token;
16 TokenKey(this.token); 15 TokenKey(this.token);
17 int get hashCode => token.charOffset; 16 int get hashCode => token.charOffset;
18 operator==(other) => other is TokenKey && token == other.token; 17 operator ==(other) => other is TokenKey && token == other.token;
19 } 18 }
20 19
21 /// Map of tokens and the first associated comment. 20 /// Map of tokens and the first associated comment.
22 /* 21 /*
23 * This implementation was chosen among several candidates for its space/time 22 * This implementation was chosen among several candidates for its space/time
24 * efficiency by empirical tests of running dartdoc on dartdoc itself. Time 23 * efficiency by empirical tests of running dartdoc on dartdoc itself. Time
25 * measurements for the use of [Compiler.commentMap]: 24 * measurements for the use of [Compiler.commentMap]:
26 * 25 *
27 * 1) Using [TokenKey] as key (this class): ~80 msec 26 * 1) Using [TokenKey] as key (this class): ~80 msec
28 * 2) Using [TokenKey] as key + storing a separate map in each script: ~120 msec 27 * 2) Using [TokenKey] as key + storing a separate map in each script: ~120 msec
29 * 3) Using [Token] as key in a [Map]: ~38000 msec 28 * 3) Using [Token] as key in a [Map]: ~38000 msec
30 * 4) Storing comments is new field in [Token]: ~20 msec 29 * 4) Storing comments is new field in [Token]: ~20 msec
31 * (Abandoned due to the increased memory usage) 30 * (Abandoned due to the increased memory usage)
32 * 5) Storing comments in an [Expando]: ~14000 msec 31 * 5) Storing comments in an [Expando]: ~14000 msec
33 * 6) Storing token/comments pairs in a linked list: ~5400 msec 32 * 6) Storing token/comments pairs in a linked list: ~5400 msec
34 */ 33 */
35 class TokenMap { 34 class TokenMap {
36 Map<TokenKey,Token> comments = new Map<TokenKey,Token>(); 35 Map<TokenKey, Token> comments = new Map<TokenKey, Token>();
37 36
38 Token operator[] (Token key) { 37 Token operator [](Token key) {
39 if (key == null) return null; 38 if (key == null) return null;
40 return comments[new TokenKey(key)]; 39 return comments[new TokenKey(key)];
41 } 40 }
42 41
43 void operator[]= (Token key, Token value) { 42 void operator []=(Token key, Token value) {
44 if (key == null) return; 43 if (key == null) return;
45 comments[new TokenKey(key)] = value; 44 comments[new TokenKey(key)] = value;
46 } 45 }
47 } 46 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/tokens/token.dart ('k') | pkg/compiler/lib/src/tracer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698