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

Unified Diff: pkg/analyzer/lib/src/summary/incremental_cache.dart

Issue 2060433003: Optimize paths comparision in source closure sorting. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/incremental_cache_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/incremental_cache.dart
diff --git a/pkg/analyzer/lib/src/summary/incremental_cache.dart b/pkg/analyzer/lib/src/summary/incremental_cache.dart
index f1bc3970551cf02cb36e144fc85d4ce33c833dcc..184e43c8d1ba26449f8c0ef228e847af62ec36d7 100644
--- a/pkg/analyzer/lib/src/summary/incremental_cache.dart
+++ b/pkg/analyzer/lib/src/summary/incremental_cache.dart
@@ -23,6 +23,37 @@ import 'package:crypto/crypto.dart';
const int _VERSION = 1;
/**
+ * Compare the given file paths [a] and [b]. Because paths usually have long
+ * equal prefix, comparison is done not as comparision of two generic [String]s.
+ * Instead it starts from the ends of each strings.
+ *
+ * Return `-1` if [a] is ordered before [b], `1` if `this` is ordered after [b],
+ * and zero if [a] and [b] are ordered together.
+ */
+int comparePaths(String a, String b) {
+ int thisLength = a.length;
+ int otherLength = b.length;
+ int len = (thisLength < otherLength) ? thisLength : otherLength;
+ for (int i = 0; i < len; i++) {
+ int thisCodeUnit = a.codeUnitAt(thisLength - 1 - i);
+ int otherCodeUnit = b.codeUnitAt(otherLength - 1 - i);
+ if (thisCodeUnit < otherCodeUnit) {
+ return -1;
+ }
+ if (thisCodeUnit > otherCodeUnit) {
+ return 1;
+ }
+ }
+ 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".
+ return -1;
+ }
+ if (thisLength > otherLength) {
+ return 1;
+ }
+ return 0;
+}
+
+/**
* Storage for cache data.
*/
abstract class CacheStorage {
@@ -413,7 +444,7 @@ class IncrementalCache {
Set<Source> closureSet = new Set<Source>();
_appendLibraryClosure(closureSet, librarySource);
List<Source> closureList = closureSet.toList();
- closureList.sort((a, b) => a.fullName.compareTo(b.fullName));
+ closureList.sort((a, b) => comparePaths(a.fullName, b.fullName));
return closureList;
});
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/incremental_cache_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698