Skip to content

Commit 7e5127d

Browse files
committedDec 20, 2016
Fix no_std build.
1 parent ab61890 commit 7e5127d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed
 

‎src/iface/arp_cache.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,24 @@ impl<'a> SliceCache<'a> {
6767

6868
/// Sort entries in an order suitable for `find`.
6969
fn sort(&mut self) {
70-
self.storage.sort_by_key(|&(key, _, _)| key)
70+
#[cfg(feature = "std")]
71+
fn sort(data: &mut [(IpAddress, EthernetAddress, usize)]) {
72+
data.sort_by_key(|&(key, _, _)| key)
73+
}
74+
75+
#[cfg(not(feature = "std"))]
76+
fn sort(data: &mut [(IpAddress, EthernetAddress, usize)]) {
77+
// Use an insertion sort, which performs best on 10 elements and less.
78+
for i in 1..data.len() {
79+
let mut j = i;
80+
while j > 0 && data[j-1].0 > data[j].0 {
81+
data.swap(j, j - 1);
82+
j = j - 1;
83+
}
84+
}
85+
}
86+
87+
sort(&mut self.storage)
7188
}
7289

7390
/// Find the least recently used entry.

‎src/managed.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::ops::{Deref, DerefMut};
2+
#[cfg(feature = "std")]
23
use core::borrow::BorrowMut;
34
use core::fmt;
45

0 commit comments

Comments
 (0)
Please sign in to comment.