OLD | NEW |
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 library analyzer.src.generated.interner; | 5 library analyzer.src.generated.interner; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 /** | 9 import 'package:front_end/src/scanner/interner.dart'; |
10 * The interface `Interner` defines the behavior of objects that can intern | 10 |
11 * strings. | 11 export 'package:front_end/src/scanner/interner.dart' |
12 */ | 12 show Interner, NullInterner; |
13 abstract class Interner { | |
14 /** | |
15 * Return a string that is identical to all of the other strings that have | |
16 * been interned that are equal to the given [string]. | |
17 */ | |
18 String intern(String string); | |
19 } | |
20 | 13 |
21 /** | 14 /** |
22 * The class `MappedInterner` implements an interner that uses a map to manage | 15 * The class `MappedInterner` implements an interner that uses a map to manage |
23 * the strings that have been interned. | 16 * the strings that have been interned. |
24 */ | 17 */ |
25 class MappedInterner implements Interner { | 18 class MappedInterner implements Interner { |
26 /** | 19 /** |
27 * A table mapping strings to themselves. | 20 * A table mapping strings to themselves. |
28 */ | 21 */ |
29 Map<String, String> _table = new HashMap<String, String>(); | 22 Map<String, String> _table = new HashMap<String, String>(); |
30 | 23 |
31 @override | 24 @override |
32 String intern(String string) { | 25 String intern(String string) { |
33 String original = _table[string]; | 26 String original = _table[string]; |
34 if (original == null) { | 27 if (original == null) { |
35 _table[string] = string; | 28 _table[string] = string; |
36 return string; | 29 return string; |
37 } | 30 } |
38 return original; | 31 return original; |
39 } | 32 } |
40 } | 33 } |
41 | |
42 /** | |
43 * The class `NullInterner` implements an interner that does nothing (does not | |
44 * actually intern any strings). | |
45 */ | |
46 class NullInterner implements Interner { | |
47 @override | |
48 String intern(String string) => string; | |
49 } | |
OLD | NEW |