Fix no_std build.

This commit is contained in:
whitequark 2016-12-20 22:06:36 +00:00
parent bddb5f9127
commit 53ddc9476f
2 changed files with 19 additions and 1 deletions

View File

@ -67,7 +67,24 @@ impl<'a> SliceCache<'a> {
/// Sort entries in an order suitable for `find`.
fn sort(&mut self) {
self.storage.sort_by_key(|&(key, _, _)| key)
#[cfg(feature = "std")]
fn sort(data: &mut [(IpAddress, EthernetAddress, usize)]) {
data.sort_by_key(|&(key, _, _)| key)
}
#[cfg(not(feature = "std"))]
fn sort(data: &mut [(IpAddress, EthernetAddress, usize)]) {
// Use an insertion sort, which performs best on 10 elements and less.
for i in 1..data.len() {
let mut j = i;
while j > 0 && data[j-1].0 > data[j].0 {
data.swap(j, j - 1);
j = j - 1;
}
}
}
sort(&mut self.storage)
}
/// Find the least recently used entry.

View File

@ -1,4 +1,5 @@
use core::ops::{Deref, DerefMut};
#[cfg(feature = "std")]
use core::borrow::BorrowMut;
use core::fmt;