aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-12-21 16:43:28 -0800
committerGraydon Hoare <[email protected]>2010-12-21 16:43:28 -0800
commit3504f4a4bf492886aa6cc7b2eae5d8e0100e9d51 (patch)
treeab9592156d3e9de9ce6811cbf508a7e94f1fe4d5 /src
parentrustc: Move type logic out of typeck so trans doesn't look like it's calling ... (diff)
downloadrust-3504f4a4bf492886aa6cc7b2eae5d8e0100e9d51.tar.xz
rust-3504f4a4bf492886aa6cc7b2eae5d8e0100e9d51.zip
Sort methods in object types.
Diffstat (limited to 'src')
-rw-r--r--src/comp/middle/typeck.rs7
-rw-r--r--src/lib/_str.rs25
2 files changed, 32 insertions, 0 deletions
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 8994d72d..32e80d9b 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -248,6 +248,13 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
auto methods =
_vec.map[@ast.method,method](f, obj_info.methods);
+ fn method_lteq(&method a, &method b) -> bool {
+ ret _str.lteq(a.ident, b.ident);
+ }
+
+ methods = std.sort.merge_sort[method](bind method_lteq(_,_),
+ methods);
+
auto t_obj = plain_ty(ty.ty_obj(methods));
ret t_obj;
}
diff --git a/src/lib/_str.rs b/src/lib/_str.rs
index 4ea5ca28..55fe1142 100644
--- a/src/lib/_str.rs
+++ b/src/lib/_str.rs
@@ -27,6 +27,31 @@ fn eq(&str a, &str b) -> bool {
ret true;
}
+fn lteq(&str a, &str b) -> bool {
+ let uint i = byte_len(a);
+ let uint j = byte_len(b);
+ let uint n = i;
+ if (j < n) {
+ n = j;
+ }
+
+ let uint x = 0u;
+ while (x < n) {
+ auto cha = a.(x);
+ auto chb = b.(x);
+ if (cha <= chb) {
+ ret true;
+ }
+ else if (cha > chb) {
+ ret false;
+ }
+ x += 1u;
+ }
+
+ ret i <= j;
+}
+
+
fn hash(&str s) -> uint {
// djb hash.
// FIXME: replace with murmur.