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:convert'; | 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/error.dart'; | 11 import 'package:analyzer/src/generated/error.dart'; |
12 import 'package:analyzer/src/generated/source.dart'; | 12 import 'package:analyzer/src/generated/source.dart'; |
13 import 'package:analyzer/src/summary/format.dart'; | 13 import 'package:analyzer/src/summary/format.dart'; |
14 import 'package:analyzer/src/summary/idl.dart'; | 14 import 'package:analyzer/src/summary/idl.dart'; |
15 import 'package:analyzer/src/summary/summarize_elements.dart'; | 15 import 'package:analyzer/src/summary/summarize_elements.dart'; |
16 import 'package:convert/convert.dart'; | 16 import 'package:convert/convert.dart'; |
17 import 'package:crypto/crypto.dart'; | 17 import 'package:crypto/crypto.dart'; |
18 | 18 |
19 /** | 19 /** |
20 * The version of the incremental cache. It should be incremented every time | 20 * The version of the incremental cache. It should be incremented every time |
21 * when any cache data structure is changed. | 21 * when any cache data structure is changed. |
22 */ | 22 */ |
23 const int _VERSION = 1; | 23 const int _VERSION = 1; |
24 | 24 |
25 /** | 25 /** |
26 * Compare the given file paths [a] and [b]. Because paths usually have long | |
27 * equal prefix, comparison is done not as comparision of two generic [String]s. | |
28 * Instead it starts from the ends of each strings. | |
29 * | |
30 * Return `-1` if [a] is ordered before [b], `1` if `this` is ordered after [b], | |
31 * and zero if [a] and [b] are ordered together. | |
32 */ | |
33 int comparePaths(String a, String b) { | |
34 int thisLength = a.length; | |
35 int otherLength = b.length; | |
36 int len = (thisLength < otherLength) ? thisLength : otherLength; | |
37 for (int i = 0; i < len; i++) { | |
38 int thisCodeUnit = a.codeUnitAt(thisLength - 1 - i); | |
39 int otherCodeUnit = b.codeUnitAt(otherLength - 1 - i); | |
40 if (thisCodeUnit < otherCodeUnit) { | |
41 return -1; | |
42 } | |
43 if (thisCodeUnit > otherCodeUnit) { | |
44 return 1; | |
45 } | |
46 } | |
47 if (thisLength < otherLength) { | |
Brian Wilkerson
2016/06/10 21:19:12
Couldn't these length tests come before the charac
Brian Wilkerson
2016/06/10 21:20:11
Nevermind, I realized why not as I clicked "send".
| |
48 return -1; | |
49 } | |
50 if (thisLength > otherLength) { | |
51 return 1; | |
52 } | |
53 return 0; | |
54 } | |
55 | |
56 /** | |
26 * Storage for cache data. | 57 * Storage for cache data. |
27 */ | 58 */ |
28 abstract class CacheStorage { | 59 abstract class CacheStorage { |
29 /** | 60 /** |
30 * Return bytes for the given [key], `null` if [key] is not in the storage. | 61 * Return bytes for the given [key], `null` if [key] is not in the storage. |
31 */ | 62 */ |
32 List<int> get(String key); | 63 List<int> get(String key); |
33 | 64 |
34 /** | 65 /** |
35 * Associate the [key] with the given [bytes]. | 66 * Associate the [key] with the given [bytes]. |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 /** | 437 /** |
407 * Return the whole source closure of the library with the given | 438 * Return the whole source closure of the library with the given |
408 * [librarySource]. It includes defining units and parts of the library and | 439 * [librarySource]. It includes defining units and parts of the library and |
409 * of all its directly or indirectly imported or exported libraries. | 440 * of all its directly or indirectly imported or exported libraries. |
410 */ | 441 */ |
411 List<Source> _getLibraryClosure(Source librarySource) { | 442 List<Source> _getLibraryClosure(Source librarySource) { |
412 return _libraryClosureMap.putIfAbsent(librarySource, () { | 443 return _libraryClosureMap.putIfAbsent(librarySource, () { |
413 Set<Source> closureSet = new Set<Source>(); | 444 Set<Source> closureSet = new Set<Source>(); |
414 _appendLibraryClosure(closureSet, librarySource); | 445 _appendLibraryClosure(closureSet, librarySource); |
415 List<Source> closureList = closureSet.toList(); | 446 List<Source> closureList = closureSet.toList(); |
416 closureList.sort((a, b) => a.fullName.compareTo(b.fullName)); | 447 closureList.sort((a, b) => comparePaths(a.fullName, b.fullName)); |
417 return closureList; | 448 return closureList; |
418 }); | 449 }); |
419 } | 450 } |
420 | 451 |
421 /** | 452 /** |
422 * Return the [context]-specific hash of the closure of the library with | 453 * Return the [context]-specific hash of the closure of the library with |
423 * the given [librarySource]. | 454 * the given [librarySource]. |
424 */ | 455 */ |
425 List<int> _getLibraryClosureHash(Source librarySource) { | 456 List<int> _getLibraryClosureHash(Source librarySource) { |
426 return _libraryClosureHashMap.putIfAbsent(librarySource, () { | 457 return _libraryClosureHashMap.putIfAbsent(librarySource, () { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 */ | 594 */ |
564 final String id; | 595 final String id; |
565 | 596 |
566 /** | 597 /** |
567 * The payload bundle. | 598 * The payload bundle. |
568 */ | 599 */ |
569 final PackageBundle bundle; | 600 final PackageBundle bundle; |
570 | 601 |
571 LibraryBundleWithId(this.source, this.id, this.bundle); | 602 LibraryBundleWithId(this.source, this.id, this.bundle); |
572 } | 603 } |
OLD | NEW |