Merge pull request #245 from s3bk/sorted_vector_binary_search
use a binary search for pathfinder_renderer::SortedVector
This commit is contained in:
commit
7f6374f110
|
@ -29,15 +29,9 @@ where
|
|||
|
||||
#[inline]
|
||||
pub fn push(&mut self, value: T) {
|
||||
self.array.push(value);
|
||||
let mut index = self.array.len() - 1;
|
||||
while index > 0 {
|
||||
index -= 1;
|
||||
if self.array[index] <= self.array[index + 1] {
|
||||
break;
|
||||
}
|
||||
self.array.swap(index, index + 1);
|
||||
}
|
||||
use std::cmp::Ordering;
|
||||
let index = self.array.binary_search_by(|other| other.partial_cmp(&value).unwrap_or(Ordering::Less)).unwrap_or_else(|x| x);
|
||||
self.array.insert(index, value);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in New Issue