common: Factor out the SectorHeaderIter::sort() method.
authorTilman Sauerbeck <tilman@code-monkey.de>
Sun, 12 Jan 2020 09:28:58 +0000 (10:28 +0100)
committerTilman Sauerbeck <tilman@code-monkey.de>
Sun, 12 Jan 2020 12:03:49 +0000 (13:03 +0100)
src/common/logger.rs

index c355bb3d47d1d3ab62cbd7dd893fd672925dd959..022b155f7d1b90b9667d5291dd4b8da9115b5dbb 100644 (file)
@@ -205,18 +205,7 @@ impl<'a> SectorHeaderIter<'a> {
 
         if num_elts_to_sort != 0 {
             // Sort the used directory entries.
-            for i in (1..((num_elts_to_sort + 1) / 2) + 1).rev() {
-                downheap(&mut iter.indices, i - 1, num_elts_to_sort - 1,
-                         iter.sector_header);
-            }
-
-            for i in (1..num_elts_to_sort).rev() {
-                let t = iter.indices[0];
-                iter.indices[0] = iter.indices[i];
-                iter.indices[i] = t;
-
-                downheap(&mut iter.indices, 0, i - 1, iter.sector_header);
-            }
+            iter.sort(num_elts_to_sort);
         }
 
         // Now put the indices of the unused directory entries in the array.
@@ -255,6 +244,21 @@ impl<'a> SectorHeaderIter<'a> {
 
         iter
     }
+
+    fn sort(&mut self, num_elts_to_sort: usize) {
+        for i in (1..((num_elts_to_sort + 1) / 2) + 1).rev() {
+            downheap(&mut self.indices, i - 1, num_elts_to_sort - 1,
+                     self.sector_header);
+        }
+
+        for i in (1..num_elts_to_sort).rev() {
+            let t = self.indices[0];
+            self.indices[0] = self.indices[i];
+            self.indices[i] = t;
+
+            downheap(&mut self.indices, 0, i - 1, self.sector_header);
+        }
+    }
 }
 
 impl<'a> Iterator for SectorHeaderIter<'a> {