Optimize TyKind::eq
.
This commit is contained in:
parent
14ea63a7e0
commit
1dbed69465
@ -310,47 +310,51 @@ fn clone(&self) -> Self {
|
|||||||
impl<I: Interner> PartialEq for TyKind<I> {
|
impl<I: Interner> PartialEq for TyKind<I> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &TyKind<I>) -> bool {
|
fn eq(&self, other: &TyKind<I>) -> bool {
|
||||||
tykind_discriminant(self) == tykind_discriminant(other)
|
// You might expect this `match` to be preceded with this:
|
||||||
&& match (self, other) {
|
//
|
||||||
(Int(a_i), Int(b_i)) => a_i == b_i,
|
// tykind_discriminant(self) == tykind_discriminant(other) &&
|
||||||
(Uint(a_u), Uint(b_u)) => a_u == b_u,
|
//
|
||||||
(Float(a_f), Float(b_f)) => a_f == b_f,
|
// but the data patterns in practice are such that a comparison
|
||||||
(Adt(a_d, a_s), Adt(b_d, b_s)) => a_d == b_d && a_s == b_s,
|
// succeeds 99%+ of the time, and it's faster to omit it.
|
||||||
(Foreign(a_d), Foreign(b_d)) => a_d == b_d,
|
match (self, other) {
|
||||||
(Array(a_t, a_c), Array(b_t, b_c)) => a_t == b_t && a_c == b_c,
|
(Int(a_i), Int(b_i)) => a_i == b_i,
|
||||||
(Slice(a_t), Slice(b_t)) => a_t == b_t,
|
(Uint(a_u), Uint(b_u)) => a_u == b_u,
|
||||||
(RawPtr(a_t), RawPtr(b_t)) => a_t == b_t,
|
(Float(a_f), Float(b_f)) => a_f == b_f,
|
||||||
(Ref(a_r, a_t, a_m), Ref(b_r, b_t, b_m)) => a_r == b_r && a_t == b_t && a_m == b_m,
|
(Adt(a_d, a_s), Adt(b_d, b_s)) => a_d == b_d && a_s == b_s,
|
||||||
(FnDef(a_d, a_s), FnDef(b_d, b_s)) => a_d == b_d && a_s == b_s,
|
(Foreign(a_d), Foreign(b_d)) => a_d == b_d,
|
||||||
(FnPtr(a_s), FnPtr(b_s)) => a_s == b_s,
|
(Array(a_t, a_c), Array(b_t, b_c)) => a_t == b_t && a_c == b_c,
|
||||||
(Dynamic(a_p, a_r, a_repr), Dynamic(b_p, b_r, b_repr)) => {
|
(Slice(a_t), Slice(b_t)) => a_t == b_t,
|
||||||
a_p == b_p && a_r == b_r && a_repr == b_repr
|
(RawPtr(a_t), RawPtr(b_t)) => a_t == b_t,
|
||||||
}
|
(Ref(a_r, a_t, a_m), Ref(b_r, b_t, b_m)) => a_r == b_r && a_t == b_t && a_m == b_m,
|
||||||
(Closure(a_d, a_s), Closure(b_d, b_s)) => a_d == b_d && a_s == b_s,
|
(FnDef(a_d, a_s), FnDef(b_d, b_s)) => a_d == b_d && a_s == b_s,
|
||||||
(Generator(a_d, a_s, a_m), Generator(b_d, b_s, b_m)) => {
|
(FnPtr(a_s), FnPtr(b_s)) => a_s == b_s,
|
||||||
a_d == b_d && a_s == b_s && a_m == b_m
|
(Dynamic(a_p, a_r, a_repr), Dynamic(b_p, b_r, b_repr)) => {
|
||||||
}
|
a_p == b_p && a_r == b_r && a_repr == b_repr
|
||||||
(GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g == b_g,
|
|
||||||
(
|
|
||||||
&GeneratorWitnessMIR(ref a_d, ref a_s),
|
|
||||||
&GeneratorWitnessMIR(ref b_d, ref b_s),
|
|
||||||
) => a_d == b_d && a_s == b_s,
|
|
||||||
(Tuple(a_t), Tuple(b_t)) => a_t == b_t,
|
|
||||||
(Alias(a_i, a_p), Alias(b_i, b_p)) => a_i == b_i && a_p == b_p,
|
|
||||||
(Param(a_p), Param(b_p)) => a_p == b_p,
|
|
||||||
(Bound(a_d, a_b), Bound(b_d, b_b)) => a_d == b_d && a_b == b_b,
|
|
||||||
(Placeholder(a_p), Placeholder(b_p)) => a_p == b_p,
|
|
||||||
(Infer(a_t), Infer(b_t)) => a_t == b_t,
|
|
||||||
(Error(a_e), Error(b_e)) => a_e == b_e,
|
|
||||||
(Bool, Bool) | (Char, Char) | (Str, Str) | (Never, Never) => true,
|
|
||||||
_ => {
|
|
||||||
debug_assert!(
|
|
||||||
false,
|
|
||||||
"This branch must be unreachable, maybe the match is missing an arm? self = self = {self:?}, other = {other:?}"
|
|
||||||
);
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
(Closure(a_d, a_s), Closure(b_d, b_s)) => a_d == b_d && a_s == b_s,
|
||||||
|
(Generator(a_d, a_s, a_m), Generator(b_d, b_s, b_m)) => {
|
||||||
|
a_d == b_d && a_s == b_s && a_m == b_m
|
||||||
|
}
|
||||||
|
(GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g == b_g,
|
||||||
|
(&GeneratorWitnessMIR(ref a_d, ref a_s), &GeneratorWitnessMIR(ref b_d, ref b_s)) => {
|
||||||
|
a_d == b_d && a_s == b_s
|
||||||
|
}
|
||||||
|
(Tuple(a_t), Tuple(b_t)) => a_t == b_t,
|
||||||
|
(Alias(a_i, a_p), Alias(b_i, b_p)) => a_i == b_i && a_p == b_p,
|
||||||
|
(Param(a_p), Param(b_p)) => a_p == b_p,
|
||||||
|
(Bound(a_d, a_b), Bound(b_d, b_b)) => a_d == b_d && a_b == b_b,
|
||||||
|
(Placeholder(a_p), Placeholder(b_p)) => a_p == b_p,
|
||||||
|
(Infer(a_t), Infer(b_t)) => a_t == b_t,
|
||||||
|
(Error(a_e), Error(b_e)) => a_e == b_e,
|
||||||
|
(Bool, Bool) | (Char, Char) | (Str, Str) | (Never, Never) => true,
|
||||||
|
_ => {
|
||||||
|
debug_assert!(
|
||||||
|
tykind_discriminant(self) != tykind_discriminant(other),
|
||||||
|
"This branch must be unreachable, maybe the match is missing an arm? self = self = {self:?}, other = {other:?}"
|
||||||
|
);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,7 +412,7 @@ fn cmp(&self, other: &TyKind<I>) -> Ordering {
|
|||||||
(Error(a_e), Error(b_e)) => a_e.cmp(b_e),
|
(Error(a_e), Error(b_e)) => a_e.cmp(b_e),
|
||||||
(Bool, Bool) | (Char, Char) | (Str, Str) | (Never, Never) => Ordering::Equal,
|
(Bool, Bool) | (Char, Char) | (Str, Str) | (Never, Never) => Ordering::Equal,
|
||||||
_ => {
|
_ => {
|
||||||
debug_assert!(false, "This branch must be unreachable, maybe the match is missing an arm? self = self = {self:?}, other = {other:?}");
|
debug_assert!(false, "This branch must be unreachable, maybe the match is missing an arm? self = {self:?}, other = {other:?}");
|
||||||
Ordering::Equal
|
Ordering::Equal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user