From cc0c0be45a995d4c7a55086189bca2a3daa343fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 29 Jan 2022 02:17:23 +1300 Subject: [PATCH] Save a pointer by passing around an Arc<[T]> instead of Arc> --- lib/src/action.rs | 4 ++-- lib/src/action/workingdata.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/src/action.rs b/lib/src/action.rs index fb0ce180..7c2cd1a5 100644 --- a/lib/src/action.rs +++ b/lib/src/action.rs @@ -114,7 +114,7 @@ pub async fn worker( trace!("out of throttle, starting action process"); last = Instant::now(); - let events = Arc::new(set.drain(..).collect()); + let events = Arc::from(set.drain(..).collect::>().into_boxed_slice()); let action = Action::new(Arc::clone(&events)); debug!(?action, "action constructed"); @@ -157,7 +157,7 @@ pub async fn worker( #[derive(Clone)] struct ActionOutcome { - events: Arc>, // TODO: make this Arc<[Event]> + events: Arc<[Event]>, working: Receiver, process: ProcessHolder, errors_c: mpsc::Sender, diff --git a/lib/src/action/workingdata.rs b/lib/src/action/workingdata.rs index 7f8a9b55..892f4249 100644 --- a/lib/src/action/workingdata.rs +++ b/lib/src/action/workingdata.rs @@ -127,18 +127,18 @@ impl Default for WorkingData { /// /// The [`Action::outcome()`] method is the only way to set the outcome of the action, and it _must_ /// be called before the handler returns. -#[derive(Debug, Default)] +#[derive(Debug)] pub struct Action { /// The collected events which triggered the action. - pub events: Arc>, + pub events: Arc<[Event]>, pub(super) outcome: Arc>, } impl Action { - pub(super) fn new(events: Arc>) -> Self { + pub(super) fn new(events: Arc<[Event]>) -> Self { Self { events, - ..Self::default() + outcome: Default::default(), } } @@ -170,7 +170,7 @@ pub struct PreSpawn { pub command: Vec, /// The collected events which triggered the action this command issues from. - pub events: Arc>, + pub events: Arc<[Event]>, command_w: Weak>, } @@ -179,7 +179,7 @@ impl PreSpawn { pub(super) fn new( command: Command, cmd: Vec, - events: Arc>, + events: Arc<[Event]>, ) -> (Self, Arc>) { let arc = Arc::new(Mutex::new(command)); ( @@ -220,7 +220,7 @@ pub struct PostSpawn { pub command: Vec, /// The collected events which triggered the action the command issues from. - pub events: Arc>, + pub events: Arc<[Event]>, /// The process ID or the process group ID. pub id: u32,