Skip to content

Commit b510a74

Browse files
mbrubeckbrson
authored andcommitted
Cleanup: Remove uneccesary generic_cmp function.
1 parent 9c5c108 commit b510a74

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

src/comp/middle/trans.rs

+13-27
Original file line numberDiff line numberDiff line change
@@ -1536,63 +1536,49 @@ fn compare_scalar_types(cx: @block_ctxt, lhs: ValueRef, rhs: ValueRef,
15361536
// A helper function to do the actual comparison of scalar values.
15371537
fn compare_scalar_values(cx: @block_ctxt, lhs: ValueRef, rhs: ValueRef,
15381538
nt: scalar_type, op: ast::binop) -> ValueRef {
1539-
let cmp = alt nt {
1539+
alt nt {
15401540
nil_type. {
15411541
// We don't need to do actual comparisons for nil.
15421542
// () == () holds but () < () does not.
15431543
alt op {
1544-
ast::eq. | ast::le. | ast::ge. { 1u }
1545-
ast::ne. | ast::lt. | ast::gt. { 0u }
1544+
ast::eq. | ast::le. | ast::ge. { ret C_bool(true); }
1545+
ast::ne. | ast::lt. | ast::gt. { ret C_bool(false); }
15461546
}
15471547
}
15481548
floating_point. {
1549-
alt op {
1549+
let cmp = alt op {
15501550
ast::eq. { lib::llvm::LLVMRealOEQ }
15511551
ast::ne. { lib::llvm::LLVMRealUNE }
15521552
ast::lt. { lib::llvm::LLVMRealOLT }
15531553
ast::le. { lib::llvm::LLVMRealOLE }
15541554
ast::gt. { lib::llvm::LLVMRealOGT }
15551555
ast::ge. { lib::llvm::LLVMRealOGE }
1556-
}
1556+
};
1557+
ret FCmp(cx, cmp, lhs, rhs);
15571558
}
15581559
signed_int. {
1559-
alt op {
1560+
let cmp = alt op {
15601561
ast::eq. { lib::llvm::LLVMIntEQ }
15611562
ast::ne. { lib::llvm::LLVMIntNE }
15621563
ast::lt. { lib::llvm::LLVMIntSLT }
15631564
ast::le. { lib::llvm::LLVMIntSLE }
15641565
ast::gt. { lib::llvm::LLVMIntSGT }
15651566
ast::ge. { lib::llvm::LLVMIntSGE }
1566-
}
1567+
};
1568+
ret ICmp(cx, cmp, lhs, rhs);
15671569
}
15681570
unsigned_int. {
1569-
alt op {
1571+
let cmp = alt op {
15701572
ast::eq. { lib::llvm::LLVMIntEQ }
15711573
ast::ne. { lib::llvm::LLVMIntNE }
15721574
ast::lt. { lib::llvm::LLVMIntULT }
15731575
ast::le. { lib::llvm::LLVMIntULE }
15741576
ast::gt. { lib::llvm::LLVMIntUGT }
15751577
ast::ge. { lib::llvm::LLVMIntUGE }
1576-
}
1578+
};
1579+
ret ICmp(cx, cmp, lhs, rhs);
15771580
}
1578-
};
1579-
// FIXME: This wouldn't be necessary if we could bind methods off of
1580-
// objects and therefore abstract over FCmp and ICmp (issue #435). Then
1581-
// we could just write, e.g., "cmp_fn = bind FCmp(cx, _, _, _);" in
1582-
// the above, and "auto eq_result = cmp_fn(eq_cmp, lhs, rhs);" in the
1583-
// below.
1584-
1585-
fn generic_cmp(cx: @block_ctxt, nt: scalar_type, op: uint, lhs: ValueRef,
1586-
rhs: ValueRef) -> ValueRef {
1587-
let r: ValueRef;
1588-
if nt == nil_type {
1589-
r = C_bool(op != 0u);
1590-
} else if nt == floating_point {
1591-
r = FCmp(cx, op, lhs, rhs);
1592-
} else { r = ICmp(cx, op, lhs, rhs); }
1593-
ret r;
1594-
}
1595-
ret generic_cmp(cx, nt, cmp, lhs, rhs);
1581+
}
15961582
}
15971583

15981584
type val_pair_fn = fn(@block_ctxt, ValueRef, ValueRef) -> @block_ctxt;

0 commit comments

Comments
 (0)