let header_a = §or_header[a as usize];
let header_b = §or_header[b as usize];
- // Latest entries come first.
- if header_a.start_time > header_b.start_time {
+ if header_a.starts_recording() && header_b.starts_recording() {
+ // Latest entries come first.
+ if header_a.start_time > header_b.start_time {
+ -1
+ } else if header_a.start_time < header_b.start_time {
+ 1
+ } else {
+ 0
+ }
+ } else if header_a.starts_recording() {
+ -1
+ } else if header_b.starts_recording() {
+ 1
+ } else if a < b {
-1
- } else if header_a.start_time < header_b.start_time {
+ } else if a > b {
1
} else {
0
indices: [0; NUM_SECTORS]
};
- let mut num_used = 0;
-
- // Put the indices of the used directory entries at the beginning
- // of the array. Ignore the unused ones since we are not going
- // to sort them anyway.
for i in 0..NUM_SECTORS {
- let sector_header = &iter.sector_header[i];
-
- if sector_header.starts_recording() {
- iter.indices[num_used] = i as u16;
- num_used += 1;
- }
+ iter.indices[i] = i as u16;
}
- let num_elts_to_sort = num_used;
-
- if num_elts_to_sort != 0 {
- // Sort the used directory entries.
- iter.sort(num_elts_to_sort);
- }
-
- // Now put the indices of the unused directory entries in the array.
- if num_used == 0 {
- for i in 0..NUM_SECTORS {
- iter.indices[i] = i as u16;
- }
- } else {
- let latest_used = iter.indices[0] as usize;
- let mut offset_unused = num_used;
-
- // First put the entries that come after the latest one in use...
- for i in (latest_used + 1)..NUM_SECTORS {
- let sector_header = &iter.sector_header[i];
-
- if !sector_header.is_in_use() {
- iter.indices[offset_unused] = i as u16;
- offset_unused += 1;
- }
- }
-
- // ... then wrap around if necessary.
- for i in 0..latest_used {
- let sector_header = &iter.sector_header[i];
-
- if !sector_header.is_in_use() {
- iter.indices[offset_unused] = i as u16;
- offset_unused += 1;
- }
- }
- }
+ iter.sort(NUM_SECTORS);
// XXX:
// Need to handle those sectors that don't start recordings