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

Unified Diff: lib/compiler/implementation/scanner/token.dart

Issue 10310040: Sort the output (for now just the classes and instance members). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase Created 8 years, 7 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
Index: lib/compiler/implementation/scanner/token.dart
diff --git a/lib/compiler/implementation/scanner/token.dart b/lib/compiler/implementation/scanner/token.dart
index ddd921b074745f311777c71ec04380a0e8b2f4a4..4405d76878d5fbacea9fad2881816721bf437540 100644
--- a/lib/compiler/implementation/scanner/token.dart
+++ b/lib/compiler/implementation/scanner/token.dart
@@ -126,7 +126,8 @@ class StringToken extends Token {
String slowToString() => value.slowToString();
}
-interface SourceString extends Hashable, Iterable<int> default StringWrapper {
+interface SourceString extends Comparable, Hashable, Iterable<int>
+ default StringWrapper {
const SourceString(String string);
void printOn(StringBuffer sb);
@@ -146,6 +147,20 @@ interface SourceString extends Hashable, Iterable<int> default StringWrapper {
bool isPrivate();
}
+int sourceStringCompare(SourceString string1, SourceString string2) {
+ Iterator<int> iterator1 = string1.iterator();
+ Iterator<int> iterator2 = string2.iterator();
+ while (iterator1.hasNext()) {
+ if (!iterator2.hasNext()) return 1;
+ int char1 = iterator1.next();
+ int char2 = iterator2.next();
+ int comparison = char1.compareTo(char2);
+ if (comparison != 0) return comparison;
+ }
+ if (iterator2.hasNext()) return -1;
+ return 0;
+}
+
class StringWrapper implements SourceString {
final String stringValue;
@@ -153,6 +168,14 @@ class StringWrapper implements SourceString {
int hashCode() => stringValue.hashCode();
+ int compareTo(SourceString other) {
+ if (other is StringWrapper) {
+ StringWrapper otherWrapper = other;
+ return stringValue.compareTo(otherWrapper.stringValue);
+ }
+ return sourceStringCompare(this, other);
+ }
+
bool operator ==(other) {
return other is SourceString && toString() == other.slowToString();
}

Powered by Google App Engine
This is Rietveld 408576698