Skip to content

Commit 699bcac

Browse files
committed
use HashMap::entry
1 parent 95b354d commit 699bcac

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

datafusion/functions-aggregate/src/first_last.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,14 @@ where
524524
continue;
525525
}
526526

527-
if !result.contains_key(&group_idx)
528-
|| comparator
529-
.compare(*result.get(&group_idx).unwrap(), idx_in_val)
530-
.is_gt()
531-
{
532-
result.insert(group_idx, idx_in_val);
533-
}
527+
result
528+
.entry(group_idx)
529+
.and_modify(|x| {
530+
if comparator.compare(*x, idx_in_val).is_gt() {
531+
*x = idx_in_val;
532+
}
533+
})
534+
.or_insert(idx_in_val);
534535
}
535536

536537
Ok(result)

0 commit comments

Comments
 (0)