From 2e89e9893159441459c971e9d6d35e438b83609c Mon Sep 17 00:00:00 2001 From: urben1680 <55257931+urben1680@users.noreply.github.com> Date: Sat, 5 Oct 2024 03:35:44 +0200 Subject: [PATCH] Deprecate `Events::oldest_id` (#15658) # Objective Fixes #15617 ## Solution The original author confirmed it was not intentional that both these methods exist. They do the same, one has the better implementation and the other the better name. ## Testing I just ran the unit tests of the module. --- ## Migration Guide - Change usages of `Events::oldest_id` to `Events::oldest_event_count` - If `Events::oldest_id` was used to get the actual oldest `EventId::id`, note that the deprecated method never reliably did that in the first place as the buffers may contain no id currently. --- crates/bevy_ecs/src/event/collections.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/bevy_ecs/src/event/collections.rs b/crates/bevy_ecs/src/event/collections.rs index 4c9bc1996f8da..c04512ba62bba 100644 --- a/crates/bevy_ecs/src/event/collections.rs +++ b/crates/bevy_ecs/src/event/collections.rs @@ -114,9 +114,7 @@ impl Default for Events { impl Events { /// Returns the index of the oldest event stored in the event buffer. pub fn oldest_event_count(&self) -> usize { - self.events_a - .start_event_count - .min(self.events_b.start_event_count) + self.events_a.start_event_count } /// "Sends" an `event` by writing it to the current event buffer. @@ -279,7 +277,7 @@ impl Events { /// Get a specific event by id if it still exists in the events buffer. pub fn get_event(&self, id: usize) -> Option<(&E, EventId)> { - if id < self.oldest_id() { + if id < self.oldest_event_count() { return None; } @@ -291,11 +289,6 @@ impl Events { .map(|instance| (&instance.event, instance.event_id)) } - /// Oldest id still in the events buffer. - pub fn oldest_id(&self) -> usize { - self.events_a.start_event_count - } - /// Which event buffer is this event id a part of. fn sequence(&self, id: usize) -> &EventSequence { if id < self.events_b.start_event_count {