chiark / gitweb /
Optimise into_unprepared slightly
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 May 2022 01:37:33 +0000 (02:37 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 May 2022 01:37:33 +0000 (02:37 +0100)
Prompted by seeing this optimisation at what ought to be a call site
of this method.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/updates.rs

index 216ca07cf1d5cfef6e961b08ae2231a50c7ba737..68821f5c2d225e8c38de5c7be31194d6c09bb739 100644 (file)
@@ -1013,10 +1013,14 @@ impl PreparedUpdate {
 impl Vec<(PieceId, PieceUpdateOps)> {
   fn into_unprepared(self, by_client: IsResponseToClientOp)
                      -> UnpreparedUpdates {
-    vec![Box::new(
-      move |buf: &mut PrepareUpdatesBuffer| {
-        buf.piece_updates(self, &by_client)
-      })]
+    if self.len() != 0 {
+      vec![Box::new(
+        move |buf: &mut PrepareUpdatesBuffer| {
+          buf.piece_updates(self, &by_client)
+        })]
+    } else {
+      default()
+    }
   }
 }