refactor(eval/builtins/intersectAttrs): use cmp for three-way comparison

There is no point in separately checking lt/eq/gt separately when we
always need the full ordering anyway.

Change-Id: I993108029d205ac17f01acdb6dbf9b2f0cd80f28
Reviewed-on: https://cl.snix.dev/c/snix/+/30372
Reviewed-by: Florian Klink <flokli@flokli.de>
Tested-by: besadii
This commit is contained in:
edef 2025-05-01 14:07:30 +00:00
parent 3d95109328
commit bcb8438856

View file

@ -811,7 +811,8 @@ mod pure_builtins {
// We opted for this implementation over simpler ones because of the
// heavy use of this function in nixpkgs.
loop {
if left.0 == right.0 {
match left.0.cmp(right.0) {
Ordering::Equal => {
out.insert(right.0.clone(), right.1.clone());
left = match left_iter.next() {
@ -823,24 +824,19 @@ mod pure_builtins {
Some(x) => x,
None => break,
};
continue;
}
if left.0 < right.0 {
Ordering::Less => {
left = match left_iter.next() {
Some(x) => x,
None => break,
};
continue;
}
if right.0 < left.0 {
Ordering::Greater => {
right = match right_iter.next() {
Some(x) => x,
None => break,
};
continue;
}
}
}