| OLD | NEW |
| 1 library tokenizer; | 1 library tokenizer; |
| 2 | 2 |
| 3 import 'dart:collection'; | 3 import 'dart:collection'; |
| 4 import 'package:html/parser.dart' show HtmlParser; | 4 import 'package:html/parser.dart' show HtmlParser; |
| 5 import 'constants.dart'; | 5 import 'constants.dart'; |
| 6 import 'inputstream.dart'; | 6 import 'inputstream.dart'; |
| 7 import 'token.dart'; | 7 import 'token.dart'; |
| 8 import 'utils.dart'; | 8 import 'utils.dart'; |
| 9 | 9 |
| 10 // Group entities by their first character, for faster lookups | 10 // Group entities by their first character, for faster lookups |
| 11 | 11 |
| 12 // TODO(jmesserly): we could use a better data structure here like a trie, if | 12 // TODO(jmesserly): we could use a better data structure here like a trie, if |
| 13 // we had it implemented in Dart. | 13 // we had it implemented in Dart. |
| 14 Map<String, List<String>> entitiesByFirstChar = (() { | 14 Map<String, List<String>> entitiesByFirstChar = (() { |
| 15 var result = {}; | 15 var result = <String, List<String>>{}; |
| 16 for (var k in entities.keys) { | 16 for (var k in entities.keys) { |
| 17 result.putIfAbsent(k[0], () => []).add(k); | 17 result.putIfAbsent(k[0], () => []).add(k); |
| 18 } | 18 } |
| 19 return result; | 19 return result; |
| 20 })(); | 20 })(); |
| 21 | 21 |
| 22 // TODO(jmesserly): lots of ways to make this faster: | 22 // TODO(jmesserly): lots of ways to make this faster: |
| 23 // - use char codes everywhere instead of 1-char strings | 23 // - use char codes everywhere instead of 1-char strings |
| 24 // - use switch instead of contains, indexOf | 24 // - use switch instead of contains, indexOf |
| 25 // - use switch instead of the sequential if tests | 25 // - use switch instead of the sequential if tests |
| (...skipping 1873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1899 } | 1899 } |
| 1900 } | 1900 } |
| 1901 | 1901 |
| 1902 if (data.length > 0) { | 1902 if (data.length > 0) { |
| 1903 _addToken(new CharactersToken(data.join())); | 1903 _addToken(new CharactersToken(data.join())); |
| 1904 } | 1904 } |
| 1905 state = dataState; | 1905 state = dataState; |
| 1906 return true; | 1906 return true; |
| 1907 } | 1907 } |
| 1908 } | 1908 } |
| OLD | NEW |