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

Side by Side Diff: pkg/analyzer/lib/src/util/fast_uri.dart

Issue 2660243002: Adapt to breaking change in SDK (TBR) (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return identical(other, this); 127 return identical(other, this);
128 } 128 }
129 return _text == other._text; 129 return _text == other._text;
130 } else if (other is Uri) { 130 } else if (other is Uri) {
131 return _fallbackUri == other; 131 return _fallbackUri == other;
132 } 132 }
133 return false; 133 return false;
134 } 134 }
135 135
136 @override 136 @override
137 bool isScheme(String scheme) {
138 String thisScheme = this.scheme;
139 if (scheme == null) return thisScheme.isEmpty;
140 if (scheme.length != thisScheme.length) return false;
141 return _compareScheme(scheme, thisScheme);
142 }
143
144 @override
137 Uri normalizePath() { 145 Uri normalizePath() {
138 return this; 146 return this;
139 } 147 }
140 148
141 @override 149 @override
142 Uri removeFragment() { 150 Uri removeFragment() {
143 return this; 151 return this;
144 } 152 }
145 153
146 @override 154 @override
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 if (_currentCacheLength > _MAX_CACHE_LENGTH_BEFORE_FLUSH) { 231 if (_currentCacheLength > _MAX_CACHE_LENGTH_BEFORE_FLUSH) {
224 _cache.clear(); 232 _cache.clear();
225 _currentCacheLength = 0; 233 _currentCacheLength = 0;
226 _currentCacheGeneration++; 234 _currentCacheGeneration++;
227 } 235 }
228 } 236 }
229 return uri; 237 return uri;
230 } 238 }
231 239
232 /** 240 /**
241 * Compares scheme characters in [scheme] and at the start of [uri].
242 *
243 * Returns `true` if [scheme] represents the same scheme as the start of
244 * [uri]. That means having the same characters, but possibly different case
245 * for letters.
246 *
247 * This function doesn't check that the characters are valid URI scheme
248 * characters. The [uri] is assumed to be valid, so if [scheme] matches
249 * it, it has to be valid too.
250 *
251 * The length should be tested before calling this function,
252 * so the scheme part of [uri] is known to have the same length as [scheme].
253 */
254 static bool _compareScheme(String scheme, String uri) {
255 for (int i = 0; i < scheme.length; i++) {
256 int schemeChar = scheme.codeUnitAt(i);
257 int uriChar = uri.codeUnitAt(i);
258 int delta = schemeChar ^ uriChar;
259 if (delta != 0) {
260 if (delta == 0x20) {
261 // Might be a case difference.
262 int lowerChar = uriChar | delta;
263 if (0x61 /*a*/ <= lowerChar && lowerChar <= 0x7a /*z*/) {
264 continue;
265 }
266 }
267 return false;
268 }
269 }
270 return true;
271 }
272
273 /**
233 * This implementation was used before 'fast-URI' in Dart VM. 274 * This implementation was used before 'fast-URI' in Dart VM.
234 */ 275 */
235 static int _computeHashUsingCombine(FastUri uri) { 276 static int _computeHashUsingCombine(FastUri uri) {
236 // This code is copied from the standard Uri implementation. 277 // This code is copied from the standard Uri implementation.
237 // It is important that Uri and FastUri generate compatible hashCodes 278 // It is important that Uri and FastUri generate compatible hashCodes
238 // because Uri and FastUri may be used as keys in the same map. 279 // because Uri and FastUri may be used as keys in the same map.
239 int combine(part, current) { 280 int combine(part, current) {
240 // The sum is truncated to 30 bits to make sure it fits into a Smi. 281 // The sum is truncated to 30 bits to make sure it fits into a Smi.
241 return (current * 31 + part.hashCode) & 0x3FFFFFFF; 282 return (current * 31 + part.hashCode) & 0x3FFFFFFF;
242 } 283 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 * Determine whether VM has the text based hash code computation in [Uri], 357 * Determine whether VM has the text based hash code computation in [Uri],
317 * or the old combine style. 358 * or the old combine style.
318 * 359 *
319 * See https://github.com/dart-lang/sdk/issues/27159 for details. 360 * See https://github.com/dart-lang/sdk/issues/27159 for details.
320 */ 361 */
321 static bool _shouldComputeHashCodeUsingText() { 362 static bool _shouldComputeHashCodeUsingText() {
322 String text = 'package:foo/foo.dart'; 363 String text = 'package:foo/foo.dart';
323 return Uri.parse(text).hashCode == text.hashCode; 364 return Uri.parse(text).hashCode == text.hashCode;
324 } 365 }
325 } 366 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698