Merge pull request #245 from s3bk/sorted_vector_binary_search

use a binary search for pathfinder_renderer::SortedVector
This commit is contained in:
Patrick Walton 2019-12-29 11:29:45 -08:00 committed by GitHub
commit 7f6374f110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 9 deletions

View File

@ -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]