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

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

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

Powered by Google App Engine
This is Rietveld 408576698