Skip to content

Commit 2f34d69

Browse files
committed
gossipsub: do early return in for an empty input
Adds a fast path in `remove_data_messages` to avoid unnecessary work when the caller provides an empty `message_ids` slice. Signed-off-by: Onur Özkan <work@onurozkan.dev>
1 parent ac1404e commit 2f34d69

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

protocols/gossipsub/src/queue.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ impl Queue {
8181
/// Remove pending low priority Publish and Forward messages.
8282
/// Returns the number of messages removed.
8383
pub(crate) fn remove_data_messages(&mut self, message_ids: &[MessageId]) -> usize {
84+
if message_ids.is_empty() {
85+
return 0;
86+
}
87+
8488
let mut count = 0;
8589
self.non_priority.retain(|message| match message {
8690
RpcOut::Publish { message_id, .. } | RpcOut::Forward { message_id, .. } => {

0 commit comments

Comments
 (0)