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

Unified Diff: pkg/analyzer/lib/src/util/fast_uri.dart

Issue 2004793002: Fix for FastUri.hashCode and hasAuthorizy (to fix ==). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: tweak Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/util/fast_uri_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/util/fast_uri_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698