Skip to content

Commit 7ac8985

Browse files
committed
Optimize OrdWithEngines::cmp.
1 parent 5b0f5ab commit 7ac8985

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

sway-core/src/engine_threading.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,19 @@ impl<T: PartialEqWithEngines> PartialEqWithEngines for [T] {
388388
}
389389
impl<T: OrdWithEngines> OrdWithEngines for [T] {
390390
fn cmp(&self, other: &Self, ctx: &OrdWithEnginesContext) -> Ordering {
391-
self.iter()
392-
.zip(other.iter())
393-
.map(|(x, y)| x.cmp(y, ctx))
394-
.find(|o| o.is_ne())
395-
.unwrap_or_else(|| self.len().cmp(&other.len()))
391+
let len_cmp = self.len().cmp(&other.len());
392+
if len_cmp != Ordering::Equal {
393+
return len_cmp;
394+
}
395+
396+
for (a, b) in self.iter().zip(other.iter()) {
397+
let cmp = a.cmp(b, ctx);
398+
if cmp != Ordering::Equal {
399+
return cmp;
400+
}
401+
}
402+
403+
Ordering::Equal
396404
}
397405
}
398406

0 commit comments

Comments
 (0)