From 4840a960b9be0aa4f8b874e2bd2d432ecc449a44 Mon Sep 17 00:00:00 2001 From: Shun Kashiwa Date: Fri, 6 Oct 2023 18:22:09 -0700 Subject: [PATCH] get rid of more String --- chorus_lib/src/core.rs | 9 ++++----- chorus_lib/src/transport/http.rs | 4 ++-- chorus_lib/src/transport/local.rs | 13 +++---------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/chorus_lib/src/core.rs b/chorus_lib/src/core.rs index 8ab9a2c..ed2d853 100644 --- a/chorus_lib/src/core.rs +++ b/chorus_lib/src/core.rs @@ -317,7 +317,7 @@ pub trait Choreography { /// The type parameter `TargetLocation` is the target `ChoreographyLocation`. pub trait Transport { /// Returns a list of locations. - fn locations(&self) -> Vec; + fn locations(&self) -> Vec<&'static str>; /// Sends a message from `from` to `to`. fn send(&self, from: &str, to: &str, data: &V) -> (); /// Receives a message from `from` to `at`. @@ -396,7 +396,7 @@ where > { target: PhantomData, transport: &'a B, - locations: Vec, + locations: Vec<&'static str>, marker: PhantomData, projector_location_set: PhantomData, } @@ -478,15 +478,14 @@ where &self, choreo: C, ) -> R { - let locs_vec = - Vec::from_iter(S::to_string_list().into_iter().map(|s| s.to_string())); + let locs_vec = S::to_string_list(); for location in &locs_vec { if *location == T::name().to_string() { let op = EppOp { target: PhantomData::, transport: self.transport, - locations: locs_vec.clone(), + locations: locs_vec, marker: PhantomData::, projector_location_set: PhantomData::, }; diff --git a/chorus_lib/src/transport/http.rs b/chorus_lib/src/transport/http.rs index e3b9cc9..8427758 100644 --- a/chorus_lib/src/transport/http.rs +++ b/chorus_lib/src/transport/http.rs @@ -130,8 +130,8 @@ impl<'a, L: LocationSet, TLocation> Drop for HttpTransport<'a, L, TLocation> { impl<'a, L: LocationSet, TLocation: ChoreographyLocation> Transport for HttpTransport<'a, L, TLocation> { - fn locations(&self) -> Vec { - Vec::from_iter(self.config.keys().map(|s| s.to_string())) + fn locations(&self) -> Vec<&'static str> { + self.config.keys().cloned().collect() } fn send(&self, from: &str, to: &str, data: &V) -> () { diff --git a/chorus_lib/src/transport/local.rs b/chorus_lib/src/transport/local.rs index 9419f53..22be7d1 100644 --- a/chorus_lib/src/transport/local.rs +++ b/chorus_lib/src/transport/local.rs @@ -124,7 +124,7 @@ impl LocalTransportChannelBuilder { /// /// All locations must share the same `LocalTransportChannel` instance. `LocalTransportChannel` implements `Clone` so that it can be shared across threads. pub struct LocalTransport { - internal_locations: Vec, + internal_locations: Vec<&'static str>, location_set: PhantomData, local_channel: LocalTransportChannel, target_location: PhantomData, @@ -135,15 +135,8 @@ impl LocalTransport { pub fn new(target: TargetLocation, local_channel: LocalTransportChannel) -> Self { _ = target; - let locations_list = L::to_string_list(); - - let mut locations_vec = Vec::new(); - for loc in locations_list.clone() { - locations_vec.push(loc.to_string()); - } - LocalTransport { - internal_locations: locations_vec, + internal_locations: L::to_string_list(), location_set: PhantomData, local_channel, target_location: PhantomData, @@ -154,7 +147,7 @@ impl LocalTransport { impl Transport for LocalTransport { - fn locations(&self) -> Vec { + fn locations(&self) -> Vec<&'static str> { return self.internal_locations.clone(); }