OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:collection'; | 5 import 'dart:collection'; |
6 | 6 |
7 /** | 7 /** |
8 * Implementation of [Uri] that understands only a limited set of valid | 8 * Implementation of [Uri] that understands only a limited set of valid |
9 * URI formats, but works fast. In practice Dart code almost always uses such | 9 * URI formats, but works fast. In practice Dart code almost always uses such |
10 * limited URI format, so almost always can be processed fast. | 10 * limited URI format, so almost always can be processed fast. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 @override | 55 @override |
56 bool get hasAuthority => _hasEmptyAuthority; | 56 bool get hasAuthority => _hasEmptyAuthority; |
57 | 57 |
58 @override | 58 @override |
59 bool get hasEmptyPath => _path.isEmpty; | 59 bool get hasEmptyPath => _path.isEmpty; |
60 | 60 |
61 @override | 61 @override |
62 bool get hasFragment => false; | 62 bool get hasFragment => false; |
63 | 63 |
64 @override | 64 @override |
65 int get hashCode => _text.hashCode; | 65 int get hashCode { |
| 66 // This code is copied from the standard Uri implementation. |
| 67 // It is important that Uri and FastUri generate compatible hashCodes |
| 68 // because Uri and FastUri may be used as keys in the same map. |
| 69 int combine(part, current) { |
| 70 // The sum is truncated to 30 bits to make sure it fits into a Smi. |
| 71 return (current * 31 + part.hashCode) & 0x3FFFFFFF; |
| 72 } |
| 73 return _hashCode ??= combine( |
| 74 scheme, |
| 75 combine( |
| 76 userInfo, |
| 77 combine( |
| 78 host, |
| 79 combine(port, |
| 80 combine(path, combine(query, combine(fragment, 1))))))); |
| 81 } |
66 | 82 |
67 @override | 83 @override |
68 bool get hasPort => false; | 84 bool get hasPort => false; |
69 | 85 |
70 @override | 86 @override |
71 bool get hasQuery => false; | 87 bool get hasQuery => false; |
72 | 88 |
73 @override | 89 @override |
74 bool get hasScheme => _scheme.isNotEmpty; | 90 bool get hasScheme => _scheme.isNotEmpty; |
75 | 91 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 hasEmptyAuthority = true; | 282 hasEmptyAuthority = true; |
267 path = path.substring(2); | 283 path = path.substring(2); |
268 if (!path.startsWith('/')) { | 284 if (!path.startsWith('/')) { |
269 return null; | 285 return null; |
270 } | 286 } |
271 } | 287 } |
272 return new FastUri._(_currentCacheGeneration, text, scheme, | 288 return new FastUri._(_currentCacheGeneration, text, scheme, |
273 hasEmptyAuthority, path, lastSlashIndex); | 289 hasEmptyAuthority, path, lastSlashIndex); |
274 } | 290 } |
275 } | 291 } |
OLD | NEW |