chore(query): remove extra clone
use std::cmp::Ordering;
use std::cmp::Ordering::Less;
+use std::intrinsics::assume;
use std::mem;
use std::ptr;
@@ -75,12 +76,16 @@ impl TopKSorter {
fn push_value<T: ValueType>(&mut self, value: T::ScalarRef<'_>) -> bool
where for<'a> T::ScalarRef<'a>: Ord {
let order = self.ordering();
- let data = self.data[0].clone();
- let data = data.as_ref();
+ unsafe {
+ assume(self.data.len() == self.limit);
+ }
+ let data = self.data[0].as_ref();
let data = T::try_downcast_scalar(&data).unwrap();
+
let value = T::upcast_gat(value);
if Ord::cmp(&data, &value) != order {
+ drop(data);
self.data[0] = T::upcast_scalar(T::to_owned_scalar(value));
self.adjust();
true
