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

Unified Diff: pkg/compiler/lib/src/elements/elements.dart

Issue 2221273002: dart2js: Sort libraries by Uri only. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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 | « pkg/compiler/lib/src/elements/common.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/elements/elements.dart
diff --git a/pkg/compiler/lib/src/elements/elements.dart b/pkg/compiler/lib/src/elements/elements.dart
index 67cdd60f7bada3f334b3511598df19f73135b08b..1b6f5469c767d761f57dc43398974f65bc857149 100644
--- a/pkg/compiler/lib/src/elements/elements.dart
+++ b/pkg/compiler/lib/src/elements/elements.dart
@@ -693,9 +693,9 @@ class Elements {
/// on the source code order.
static int compareByPosition(Element a, Element b) {
if (identical(a, b)) return 0;
- int r = a.library.compareTo(b.library);
+ int r = _compareLibraries(a.library, b.library);
if (r != 0) return r;
- r = a.compilationUnit.compareTo(b.compilationUnit);
+ r = _compareCompilationUnits(a.compilationUnit, b.compilationUnit);
if (r != 0) return r;
int offsetA = a.sourceOffset ?? -1;
int offsetB = b.sourceOffset ?? -1;
@@ -708,6 +708,61 @@ class Elements {
return a.hashCode.compareTo(b.hashCode);
}
+ // Somewhat stable ordering for [LibraryElement]s
+ static int _compareLibraries(LibraryElement a, LibraryElement b) {
+ if (a == b) return 0;
+
+ int byCanonicalUriPath() {
+ return a.canonicalUri.path.compareTo(b.canonicalUri.path);
+ }
+
+ // Order: platform < package < other.
+ if (a.isPlatformLibrary) {
+ if (b.isPlatformLibrary) return byCanonicalUriPath();
+ return -1;
+ }
+ if (b.isPlatformLibrary) return 1;
+
+ if (a.isPackageLibrary) {
+ if (b.isPackageLibrary) return byCanonicalUriPath();
+ return -1;
+ }
+ if (b.isPackageLibrary) return 1;
+
+ return _compareCanonicalUri(a.canonicalUri, b.canonicalUri);
+ }
+
+ static int _compareCanonicalUri(Uri a, Uri b) {
+ int r = a.scheme.compareTo(b.scheme);
+ if (r != 0) return r;
+
+ // We would like the order of 'file:' Uris to be stable across different
Siggi Cherem (dart-lang) 2016/08/09 22:11:21 Can we add an extra rule here that if scheme == fi
+ // users or different builds from temporary directories. We sort by
+ // pathSegments elements from the last to the first since that tends to find
+ // a stable distinction regardless of directory root.
+ List<String> aSegments = a.pathSegments;
+ List<String> bSegments = b.pathSegments;
+ int aI = aSegments.length;
+ int bI = bSegments.length;
+ while (aI > 0 && bI > 0) {
+ String aSegment = aSegments[--aI];
+ String bSegment = bSegments[--bI];
+ r = aSegment.compareTo(bSegment);
+ if (r != 0) return r;
+ }
+ return aI.compareTo(bI); // Shortest first.
+ }
+
+ static int _compareCompilationUnits(CompilationUnit a, CompilationUnit b) {
+ if (a == b) return 0;
+ // Compilation units are compared only within the same library so we expect
+ // the Uris to usually be clustered together with a common scheme and path
+ // prefix.
+ Uri aUri = a.script.readableUri;
+ Uri bUri = b.script.readableUri;
+ return '${aUri}'.compareTo('${bUri}');
+ }
+
static List<Element> sortedByPosition(Iterable<Element> elements) {
return elements.toList()..sort(compareByPosition);
}
@@ -932,7 +987,7 @@ abstract class LibraryElement extends Element
/// "a b.dart").
String get libraryOrScriptName;
- int compareTo(LibraryElement other);
+ //int compareTo(LibraryElement other);
Siggi Cherem (dart-lang) 2016/08/09 22:11:21 delete?
}
/// The implicit scope defined by a import declaration with a prefix clause.
« no previous file with comments | « pkg/compiler/lib/src/elements/common.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698