mirror of
https://github.com/denoland/deno.git
synced 2025-01-11 16:42:21 -05:00
cleanup(ext/web/BlobStore): avoid redundant Arc<Box<T>> alloc (#11693)
This commit is contained in:
parent
b8cfc95470
commit
1d1507384b
2 changed files with 10 additions and 13 deletions
|
@ -968,7 +968,7 @@ mod tests {
|
||||||
let specifier = blob_store.insert_object_url(
|
let specifier = blob_store.insert_object_url(
|
||||||
Blob {
|
Blob {
|
||||||
media_type: "application/typescript".to_string(),
|
media_type: "application/typescript".to_string(),
|
||||||
parts: vec![Arc::new(Box::new(InMemoryBlobPart::from(bytes)))],
|
parts: vec![Arc::new(InMemoryBlobPart::from(bytes))],
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
|
@ -15,7 +15,7 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use crate::Location;
|
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)]
|
#[derive(Clone, Default, Debug)]
|
||||||
pub struct BlobStore {
|
pub struct BlobStore {
|
||||||
|
@ -24,17 +24,14 @@ pub struct BlobStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 id = Uuid::new_v4();
|
||||||
let mut parts = self.parts.lock();
|
let mut parts = self.parts.lock();
|
||||||
parts.insert(id, Arc::new(part));
|
parts.insert(id, part);
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_part(
|
pub fn get_part(&self, id: &Uuid) -> Option<Arc<dyn BlobPart + Send + Sync>> {
|
||||||
&self,
|
|
||||||
id: &Uuid,
|
|
||||||
) -> Option<Arc<Box<dyn BlobPart + Send + Sync>>> {
|
|
||||||
let parts = self.parts.lock();
|
let parts = self.parts.lock();
|
||||||
let part = parts.get(id);
|
let part = parts.get(id);
|
||||||
part.cloned()
|
part.cloned()
|
||||||
|
@ -43,7 +40,7 @@ impl BlobStore {
|
||||||
pub fn remove_part(
|
pub fn remove_part(
|
||||||
&self,
|
&self,
|
||||||
id: &Uuid,
|
id: &Uuid,
|
||||||
) -> Option<Arc<Box<dyn BlobPart + Send + Sync>>> {
|
) -> Option<Arc<dyn BlobPart + Send + Sync>> {
|
||||||
let mut parts = self.parts.lock();
|
let mut parts = self.parts.lock();
|
||||||
parts.remove(id)
|
parts.remove(id)
|
||||||
}
|
}
|
||||||
|
@ -86,7 +83,7 @@ impl BlobStore {
|
||||||
pub struct Blob {
|
pub struct Blob {
|
||||||
pub media_type: String,
|
pub media_type: String,
|
||||||
|
|
||||||
pub parts: Vec<Arc<Box<dyn BlobPart + Send + Sync>>>,
|
pub parts: Vec<Arc<dyn BlobPart + Send + Sync>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Blob {
|
impl Blob {
|
||||||
|
@ -143,7 +140,7 @@ impl BlobPart for InMemoryBlobPart {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SlicedBlobPart {
|
pub struct SlicedBlobPart {
|
||||||
part: Arc<Box<dyn BlobPart + Send + Sync>>,
|
part: Arc<dyn BlobPart + Send + Sync>,
|
||||||
start: usize,
|
start: usize,
|
||||||
len: usize,
|
len: usize,
|
||||||
}
|
}
|
||||||
|
@ -167,7 +164,7 @@ pub fn op_blob_create_part(
|
||||||
) -> Result<Uuid, AnyError> {
|
) -> Result<Uuid, AnyError> {
|
||||||
let blob_store = state.borrow::<BlobStore>();
|
let blob_store = state.borrow::<BlobStore>();
|
||||||
let part = InMemoryBlobPart(data.to_vec());
|
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)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +195,7 @@ pub fn op_blob_slice_part(
|
||||||
}
|
}
|
||||||
|
|
||||||
let sliced_part = SlicedBlobPart { part, start, len };
|
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)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue