summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-08-14 10:27:27 +0200
committerGitHub <noreply@github.com>2021-08-14 10:27:27 +0200
commit1d1507384bca78027c9003b81465bd99a585cace (patch)
tree1645e61596cc97bd3f07e9bfe4dbb6fbf264d076
parentb8cfc9547023a30df991047e7a32e3e661faecfa (diff)
cleanup(ext/web/BlobStore): avoid redundant Arc<Box<T>> alloc (#11693)
-rw-r--r--cli/file_fetcher.rs2
-rw-r--r--ext/web/blob.rs21
2 files changed, 10 insertions, 13 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index 41c645c3a..8fda66382 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -968,7 +968,7 @@ mod tests {
let specifier = blob_store.insert_object_url(
Blob {
media_type: "application/typescript".to_string(),
- parts: vec![Arc::new(Box::new(InMemoryBlobPart::from(bytes)))],
+ parts: vec![Arc::new(InMemoryBlobPart::from(bytes))],
},
None,
);
diff --git a/ext/web/blob.rs b/ext/web/blob.rs
index 0f27553c7..2179de4a6 100644
--- a/ext/web/blob.rs
+++ b/ext/web/blob.rs
@@ -15,7 +15,7 @@ use uuid::Uuid;
use crate::Location;
-pub type PartMap = HashMap<Uuid, Arc<Box<dyn BlobPart + Send + Sync>>>;
+pub type PartMap = HashMap<Uuid, Arc<dyn BlobPart + Send + Sync>>;
#[derive(Clone, Default, Debug)]
pub struct BlobStore {
@@ -24,17 +24,14 @@ pub struct BlobStore {
}
impl BlobStore {
- pub fn insert_part(&self, part: Box<dyn BlobPart + Send + Sync>) -> Uuid {
+ pub fn insert_part(&self, part: Arc<dyn BlobPart + Send + Sync>) -> Uuid {
let id = Uuid::new_v4();
let mut parts = self.parts.lock();
- parts.insert(id, Arc::new(part));
+ parts.insert(id, part);
id
}
- pub fn get_part(
- &self,
- id: &Uuid,
- ) -> Option<Arc<Box<dyn BlobPart + Send + Sync>>> {
+ pub fn get_part(&self, id: &Uuid) -> Option<Arc<dyn BlobPart + Send + Sync>> {
let parts = self.parts.lock();
let part = parts.get(id);
part.cloned()
@@ -43,7 +40,7 @@ impl BlobStore {
pub fn remove_part(
&self,
id: &Uuid,
- ) -> Option<Arc<Box<dyn BlobPart + Send + Sync>>> {
+ ) -> Option<Arc<dyn BlobPart + Send + Sync>> {
let mut parts = self.parts.lock();
parts.remove(id)
}
@@ -86,7 +83,7 @@ impl BlobStore {
pub struct Blob {
pub media_type: String,
- pub parts: Vec<Arc<Box<dyn BlobPart + Send + Sync>>>,
+ pub parts: Vec<Arc<dyn BlobPart + Send + Sync>>,
}
impl Blob {
@@ -143,7 +140,7 @@ impl BlobPart for InMemoryBlobPart {
#[derive(Debug)]
pub struct SlicedBlobPart {
- part: Arc<Box<dyn BlobPart + Send + Sync>>,
+ part: Arc<dyn BlobPart + Send + Sync>,
start: usize,
len: usize,
}
@@ -167,7 +164,7 @@ pub fn op_blob_create_part(
) -> Result<Uuid, AnyError> {
let blob_store = state.borrow::<BlobStore>();
let part = InMemoryBlobPart(data.to_vec());
- let id = blob_store.insert_part(Box::new(part));
+ let id = blob_store.insert_part(Arc::new(part));
Ok(id)
}
@@ -198,7 +195,7 @@ pub fn op_blob_slice_part(
}
let sliced_part = SlicedBlobPart { part, start, len };
- let id = blob_store.insert_part(Box::new(sliced_part));
+ let id = blob_store.insert_part(Arc::new(sliced_part));
Ok(id)
}