core: String equality should short-circuit on pointer equality

This commit is contained in:
David Wendt 2021-11-27 20:37:52 -05:00 committed by kmeisthax
parent 29d2df5f07
commit 54fcfde1cc
1 changed files with 4 additions and 0 deletions

View File

@ -96,6 +96,10 @@ pub fn str_debug_fmt(s: &WStr, f: &mut fmt::Formatter<'_>) -> fmt::Result {
} }
pub fn str_eq(left: &WStr, right: &WStr) -> bool { pub fn str_eq(left: &WStr, right: &WStr) -> bool {
if std::ptr::eq(left, right) {
return true;
}
let (bytes, wide) = match (left.units(), right.units()) { let (bytes, wide) = match (left.units(), right.units()) {
(Units::Bytes(a), Units::Bytes(b)) => return a == b, (Units::Bytes(a), Units::Bytes(b)) => return a == b,
(Units::Wide(a), Units::Wide(b)) => return a == b, (Units::Wide(a), Units::Wide(b)) => return a == b,