Skip to content

Commit a7b965c

Browse files
committed
Avoid Wrapping LumaImage in Arc, as it contains a mechanism for efficient cloning internally
1 parent b724885 commit a7b965c

3 files changed

Lines changed: 11 additions & 15 deletions

File tree

pilatus-engineering/src/image/broadcaster.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<
5151
);
5252
if broadcaster
5353
.send(BroadcastImage {
54-
image: Arc::new(output.image),
54+
image: output.image,
5555
hash: output.meta.hash,
5656
})
5757
.is_ok()

pilatus-engineering/src/image/message.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,20 @@ impl ActorMessage for SubscribeImageMessage {
7777
#[non_exhaustive]
7878
#[derive(Debug, Clone)]
7979
pub struct BroadcastImage {
80-
pub image: Arc<LumaImage>,
80+
pub image: LumaImage,
8181
pub hash: Option<StableHash>,
8282
}
8383

8484
impl BroadcastImage {
85-
pub fn with_hash(image: impl Into<Arc<LumaImage>>, hash: Option<StableHash>) -> Self {
86-
Self {
87-
image: image.into(),
88-
hash,
89-
}
85+
pub fn with_hash(image: LumaImage, hash: Option<StableHash>) -> Self {
86+
Self { image, hash }
9087
}
9188
}
9289

9390
impl From<GetImageOk> for BroadcastImage {
9491
fn from(o: GetImageOk) -> Self {
9592
Self {
96-
image: Arc::new(o.image),
93+
image: o.image,
9794
hash: o.meta.hash,
9895
}
9996
}
@@ -113,19 +110,19 @@ impl From<LocalizableBroadcastImage> for BroadcastImage {
113110
#[non_exhaustive]
114111
#[derive(Clone)]
115112
pub struct LocalizableBroadcastImage {
116-
pub image: Arc<LumaImage>,
113+
pub image: LumaImage,
117114
pub hash: Option<StableHash>,
118115
pub projector: Option<DynamicPointProjector>,
119116
}
120117

121118
impl LocalizableBroadcastImage {
122119
pub fn with_hash_and_projector(
123-
image: impl Into<Arc<LumaImage>>,
120+
image: LumaImage,
124121
hash: Option<StableHash>,
125122
projector: Option<DynamicPointProjector>,
126123
) -> Self {
127124
Self {
128-
image: image.into(),
125+
image,
129126
hash,
130127
projector,
131128
}
@@ -166,7 +163,7 @@ pub struct GetLocalizableImageOk {
166163
impl From<GetLocalizableImageOk> for BroadcastImage {
167164
fn from(value: GetLocalizableImageOk) -> Self {
168165
Self {
169-
image: Arc::new(value.image),
166+
image: value.image,
170167
hash: value.hash,
171168
}
172169
}

pilatus-engineering/src/image/web.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::{
77
fmt::{self, Debug, Formatter},
88
marker::PhantomData,
99
num::{NonZeroU32, NonZeroU8},
10-
sync::Arc,
1110
};
1211

1312
use anyhow::anyhow;
@@ -39,7 +38,7 @@ pub trait StreamableImage: Sized {
3938
fn encode(self) -> anyhow::Result<Vec<u8>>;
4039
}
4140

42-
impl StreamableImage for Arc<LumaImage> {
41+
impl StreamableImage for LumaImage {
4342
fn encode(self) -> anyhow::Result<Vec<u8>> {
4443
let dims = self.dimensions();
4544
encode_legacy(self.buffer(), ColorType::Luma, dims, |_| Ok(()))
@@ -200,7 +199,7 @@ fn encode_dynamic_jpeg_image<T: Serialize>(
200199
}
201200
}
202201

203-
impl<T: Serialize> StreamableImage for (Arc<LumaImage>, T) {
202+
impl<T: Serialize> StreamableImage for (LumaImage, T) {
204203
fn encode(self) -> anyhow::Result<Vec<u8>> {
205204
let dims = self.0.dimensions();
206205
encode_legacy(self.0.buffer(), ColorType::Luma, dims, |b| {

0 commit comments

Comments
 (0)