Save a pointer by passing around an Arc<[T]> instead of Arc<Vec<T>>
This commit is contained in:
parent
22f081a47b
commit
cc0c0be45a
|
@ -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::<Vec<_>>().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<Vec<Event>>, // TODO: make this Arc<[Event]>
|
||||
events: Arc<[Event]>,
|
||||
working: Receiver<WorkingData>,
|
||||
process: ProcessHolder,
|
||||
errors_c: mpsc::Sender<RuntimeError>,
|
||||
|
|
|
@ -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<Vec<Event>>,
|
||||
pub events: Arc<[Event]>,
|
||||
pub(super) outcome: Arc<OnceCell<Outcome>>,
|
||||
}
|
||||
|
||||
impl Action {
|
||||
pub(super) fn new(events: Arc<Vec<Event>>) -> 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<String>,
|
||||
|
||||
/// The collected events which triggered the action this command issues from.
|
||||
pub events: Arc<Vec<Event>>,
|
||||
pub events: Arc<[Event]>,
|
||||
|
||||
command_w: Weak<Mutex<Command>>,
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ impl PreSpawn {
|
|||
pub(super) fn new(
|
||||
command: Command,
|
||||
cmd: Vec<String>,
|
||||
events: Arc<Vec<Event>>,
|
||||
events: Arc<[Event]>,
|
||||
) -> (Self, Arc<Mutex<Command>>) {
|
||||
let arc = Arc::new(Mutex::new(command));
|
||||
(
|
||||
|
@ -220,7 +220,7 @@ pub struct PostSpawn {
|
|||
pub command: Vec<String>,
|
||||
|
||||
/// The collected events which triggered the action the command issues from.
|
||||
pub events: Arc<Vec<Event>>,
|
||||
pub events: Arc<[Event]>,
|
||||
|
||||
/// The process ID or the process group ID.
|
||||
pub id: u32,
|
||||
|
|
Loading…
Reference in New Issue