Chromium Code Reviews| Index: pkg/analyzer/lib/src/util/fast_uri.dart |
| diff --git a/pkg/analyzer/lib/src/util/fast_uri.dart b/pkg/analyzer/lib/src/util/fast_uri.dart |
| index 4913dfab0817e0e83804d0b2abb80fb75dca8f23..ea4f8e87b92252a7d3ddbaaa48cae6835dd98271 100644 |
| --- a/pkg/analyzer/lib/src/util/fast_uri.dart |
| +++ b/pkg/analyzer/lib/src/util/fast_uri.dart |
| @@ -22,6 +22,7 @@ class FastUri implements Uri { |
| final int _cacheGeneration; |
| final String _text; |
| final String _scheme; |
| + final bool _hasEmptyAuthority; |
| final String _path; |
| /** |
| @@ -36,8 +37,8 @@ class FastUri implements Uri { |
| Uri _cachedFallbackUri; |
| - FastUri._(this._cacheGeneration, this._text, this._scheme, this._path, |
| - this._lastSlashIndex); |
| + FastUri._(this._cacheGeneration, this._text, this._scheme, |
| + this._hasEmptyAuthority, this._path, this._lastSlashIndex); |
| @override |
| String get authority => ''; |
| @@ -52,7 +53,7 @@ class FastUri implements Uri { |
| bool get hasAbsolutePath => path.startsWith('/'); |
| @override |
| - bool get hasAuthority => false; |
| + bool get hasAuthority => _hasEmptyAuthority; |
| @override |
| bool get hasEmptyPath => _path.isEmpty; |
| @@ -62,8 +63,19 @@ class FastUri implements Uri { |
| @override |
| int get hashCode { |
| - _hashCode ??= (scheme.hashCode * 31 + path.hashCode) & 0x3FFFFFFF; |
| - return _hashCode; |
| + // This code is copied from the standard Uri implementation. |
|
Paul Berry
2016/05/23 15:34:01
Nit: Consider including a comment explaining why i
|
| + int combine(part, current) { |
| + // The sum is truncated to 30 bits to make sure it fits into a Smi. |
| + return (current * 31 + part.hashCode) & 0x3FFFFFFF; |
| + } |
| + return _hashCode ??= combine( |
| + scheme, |
| + combine( |
| + userInfo, |
| + combine( |
| + host, |
| + combine(port, |
| + combine(path, combine(query, combine(fragment, 1))))))); |
| } |
| @override |
| @@ -262,11 +274,16 @@ class FastUri implements Uri { |
| } |
| } |
| String scheme = schemeEnd != null ? text.substring(0, schemeEnd) : ''; |
| + bool hasEmptyAuthority = false; |
| String path = text.substring(pathStart); |
| if (path.startsWith('//')) { |
| + hasEmptyAuthority = true; |
| path = path.substring(2); |
| + if (!path.startsWith('/')) { |
| + return null; |
| + } |
| } |
| - return new FastUri._( |
| - _currentCacheGeneration, text, scheme, path, lastSlashIndex); |
| + return new FastUri._(_currentCacheGeneration, text, scheme, |
| + hasEmptyAuthority, path, lastSlashIndex); |
| } |
| } |