From 4c1235ac974a59f6b719335fb875c30ee7f1aa9e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 1 May 2022 02:37:33 +0100 Subject: [PATCH] Optimise into_unprepared slightly Prompted by seeing this optimisation at what ought to be a call site of this method. Signed-off-by: Ian Jackson --- src/updates.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/updates.rs b/src/updates.rs index 216ca07c..68821f5c 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -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() + } } } -- 2.30.2