소스 검색

Fix no_std build.

whitequark 8 년 전
부모
커밋
7e5127d067
2개의 변경된 파일19개의 추가작업 그리고 1개의 파일을 삭제
  1. 18 1
      src/iface/arp_cache.rs
  2. 1 0
      src/managed.rs

+ 18 - 1
src/iface/arp_cache.rs

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

+ 1 - 0
src/managed.rs

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