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

Side by Side Diff: pkg/analyzer/lib/src/summary/incremental_cache.dart

Issue 2041963002: Start using crypto 1.1.1 and tweak MD5 computation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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 | pkg/analyzer/pubspec.yaml » ('j') | 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:convert' show ChunkedConversionSink, UTF8; 5 import 'dart:convert';
6 import 'dart:core' hide Resource; 6 import 'dart:core' hide Resource;
7 7
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/file_system/file_system.dart'; 9 import 'package:analyzer/file_system/file_system.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
11 import 'package:analyzer/src/generated/source.dart'; 11 import 'package:analyzer/src/generated/source.dart';
12 import 'package:analyzer/src/summary/format.dart'; 12 import 'package:analyzer/src/summary/format.dart';
13 import 'package:analyzer/src/summary/idl.dart'; 13 import 'package:analyzer/src/summary/idl.dart';
14 import 'package:analyzer/src/summary/summarize_elements.dart'; 14 import 'package:analyzer/src/summary/summarize_elements.dart';
15 import 'package:convert/convert.dart'; 15 import 'package:convert/convert.dart';
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 if (refSource == null) { 213 if (refSource == null) {
214 throw new StateError('Unable to resolve $refUri in $librarySource'); 214 throw new StateError('Unable to resolve $refUri in $librarySource');
215 } 215 }
216 _appendLibraryClosure(closure, refSource); 216 _appendLibraryClosure(closure, refSource);
217 } 217 }
218 contentSource.importedUris.forEach(appendLibrarySources); 218 contentSource.importedUris.forEach(appendLibrarySources);
219 contentSource.exportedUris.forEach(appendLibrarySources); 219 contentSource.exportedUris.forEach(appendLibrarySources);
220 } 220 }
221 } 221 }
222 222
223 List<int> _computeSaltedMD5OfBytes(addData(ByteConversionSink byteSink)) {
224 Digest digest;
225 ChunkedConversionSink<Digest> digestSink =
226 new ChunkedConversionSink<Digest>.withCallback((List<Digest> digests) {
227 digest = digests.single;
228 });
229 ByteConversionSink byteSink = md5.startChunkedConversion(digestSink);
230 // Add data.
231 addData(byteSink);
232 byteSink.add(configSalt);
233 // Done.
234 byteSink.close();
235 return digest.bytes;
236 }
237
223 /** 238 /**
224 * Get the content based information about the given [source], maybe `null` 239 * Get the content based information about the given [source], maybe `null`
225 * if the information is not in the cache. 240 * if the information is not in the cache.
226 */ 241 */
227 CacheSourceContent _getCacheSourceContent(Source source) { 242 CacheSourceContent _getCacheSourceContent(Source source) {
228 CacheSourceContent content = _sourceContentMap[source]; 243 CacheSourceContent content = _sourceContentMap[source];
229 if (content == null) { 244 if (content == null) {
230 String key = _getCacheSourceContentKey(source); 245 String key = _getCacheSourceContentKey(source);
231 List<int> bytes = storage.get(key); 246 List<int> bytes = storage.get(key);
232 if (bytes == null) { 247 if (bytes == null) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 }); 300 });
286 } 301 }
287 302
288 /** 303 /**
289 * Return the [context]-specific hash of the closure of the library with 304 * Return the [context]-specific hash of the closure of the library with
290 * the given [librarySource]. 305 * the given [librarySource].
291 */ 306 */
292 List<int> _getLibraryClosureHash(Source librarySource) { 307 List<int> _getLibraryClosureHash(Source librarySource) {
293 return _libraryClosureHashMap.putIfAbsent(librarySource, () { 308 return _libraryClosureHashMap.putIfAbsent(librarySource, () {
294 List<Source> closure = _getLibraryClosure(librarySource); 309 List<Source> closure = _getLibraryClosure(librarySource);
295 310 return _computeSaltedMD5OfBytes((ByteConversionSink byteSink) {
296 Digest digest; 311 for (Source source in closure) {
297 312 List<int> sourceHash = _getSourceContentHash(source);
298 var digestSink = new ChunkedConversionSink<Digest>.withCallback( 313 byteSink.add(sourceHash);
299 (List<Digest> digests) { 314 }
300 digest = digests.single;
301 }); 315 });
302
303 var byteSink = md5.startChunkedConversion(digestSink);
304
305 for (Source source in closure) {
306 List<int> sourceHash = _getSourceContentHash(source);
307 byteSink.add(sourceHash);
308 }
309 byteSink.add(configSalt);
310
311 byteSink.close();
312 // TODO(paulberry): this call to `close` should not be needed.
313 // Can be removed once
314 // https://github.com/dart-lang/crypto/issues/33
315 // is fixed – ensure the min version constraint on crypto is updated, tho.
316 // Does not cause any problems in the mean time.
317 digestSink.close();
318
319 return digest.bytes;
320 }); 316 });
321 } 317 }
322 318
323 /** 319 /**
324 * Compute a hash of the given [source] contents. 320 * Compute a hash of the given [source] contents.
325 */ 321 */
326 List<int> _getSourceContentHash(Source source) { 322 List<int> _getSourceContentHash(Source source) {
327 return _sourceContentHashMap.putIfAbsent(source, () { 323 return _sourceContentHashMap.putIfAbsent(source, () {
328 String sourceText = source.contents.data; 324 String sourceText = source.contents.data;
329 List<int> sourceBytes = UTF8.encode(sourceText); 325 List<int> sourceBytes = UTF8.encode(sourceText);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 */ 426 */
431 final String id; 427 final String id;
432 428
433 /** 429 /**
434 * The payload bundle. 430 * The payload bundle.
435 */ 431 */
436 final PackageBundle bundle; 432 final PackageBundle bundle;
437 433
438 LibraryBundleWithId(this.source, this.id, this.bundle); 434 LibraryBundleWithId(this.source, this.id, this.bundle);
439 } 435 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698