Explorar o código

Shift log vector and avoid allocation.

Jing Yang %!s(int64=5) %!d(string=hai) anos
pai
achega
4d80a496f2
Modificáronse 1 ficheiros con 2 adicións e 1 borrados
  1. 2 1
      src/log_array.rs

+ 2 - 1
src/log_array.rs

@@ -122,7 +122,8 @@ impl LogArray {
     pub fn shift(&mut self, index: Index, snapshot: bytes::Bytes) {
     pub fn shift(&mut self, index: Index, snapshot: bytes::Bytes) {
         // Discard everything before index and store the snapshot.
         // Discard everything before index and store the snapshot.
         let offset = self.check_middle_index(index);
         let offset = self.check_middle_index(index);
-        self.inner = self.inner.split_off(offset);
+        // WARNING: Potentially all entries after offset would be copied.
+        self.inner.drain(0..offset);
         self.snapshot = snapshot;
         self.snapshot = snapshot;
 
 
         // Override the first entry, we know there is at least one entry. This is not strictly
         // Override the first entry, we know there is at least one entry. This is not strictly