File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,24 @@ impl<'a> SliceCache<'a> {
67
67
68
68
/// Sort entries in an order suitable for `find`.
69
69
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 )
71
88
}
72
89
73
90
/// Find the least recently used entry.
Original file line number Diff line number Diff line change 1
1
use core:: ops:: { Deref , DerefMut } ;
2
+ #[ cfg( feature = "std" ) ]
2
3
use core:: borrow:: BorrowMut ;
3
4
use core:: fmt;
4
5
You can’t perform that action at this time.
0 commit comments