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

Unified Diff: lib/compiler/implementation/dart_backend/backend.dart

Issue 10834416: Rename elements after sorting. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | « no previous file | lib/compiler/implementation/dart_backend/renamer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/dart_backend/backend.dart
diff --git a/lib/compiler/implementation/dart_backend/backend.dart b/lib/compiler/implementation/dart_backend/backend.dart
index e65c90bd669691f7233abee768bbdbf5e6ead6ee..109595032fb5355aeff2f93f44dffcee14117327 100644
--- a/lib/compiler/implementation/dart_backend/backend.dart
+++ b/lib/compiler/implementation/dart_backend/backend.dart
@@ -104,21 +104,10 @@ class DartBackend extends Backend {
renamePlaceholders(compiler, collector, renames, imports);
// Sort elements.
- compareElements(e0, e1) {
- compareBy(x, y, f) => f(x).compareTo(f(y));
- int result = compareBy(e0, e1, (e) => e.getLibrary().uri.toString());
- if (result != 0) return result;
- return compareBy(e0, e1, (e) => e.position().charOffset);
- }
-
- final sortedTopLevels = new List<Element>.from(topLevelElements);
- sortedTopLevels.sort(compareElements);
-
+ final sortedTopLevels = sortElements(topLevelElements);
final sortedClassMembers = new Map<ClassElement, List<Element>>();
classMembers.forEach((classElement, members) {
- final sortedMembers = new List<Element>.from(members);
- sortedMembers.sort(compareElements);
- sortedClassMembers[classElement] = sortedMembers;
+ sortedClassMembers[classElement] = sortElements(members);
});
final unparser = new Unparser.withRenamer((Node node) => renames[node]);
@@ -191,3 +180,21 @@ class ReferencedElementCollector extends AbstractVisitor {
});
}
}
+
+compareBy(f) => (x, y) => f(x).compareTo(f(y));
+
+List sorted(List l, comparison) {
Roman 2012/08/21 12:37:39 'sortList'?
Anton Muhin 2012/08/21 12:57:42 sorted matches nicely Python, mind if I keep it th
+ final result = new List.from(l);
+ result.sort(comparison);
+ return result;
+}
+
+List<Element> sortElements(Collection<Element> elements) {
+ compareElements(e0, e1) {
+ int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1);
+ if (result != 0) return result;
+ return compareBy((e) => e.position().charOffset)(e0, e1);
+ }
+
+ return sorted(elements, compareElements);
+}
« no previous file with comments | « no previous file | lib/compiler/implementation/dart_backend/renamer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698