mirror of
https://github.com/servo/servo.git
synced 2025-07-24 07:40:27 +01:00
Improve Blob.Size() speed by avoid reading content
This commit is contained in:
parent
49431be44a
commit
06e29c0497
1 changed files with 6 additions and 5 deletions
|
@ -357,11 +357,12 @@ pub fn blob_parts_to_bytes(blobparts: Vec<BlobOrString>) -> Result<Vec<u8>, ()>
|
||||||
impl BlobMethods for Blob {
|
impl BlobMethods for Blob {
|
||||||
// https://w3c.github.io/FileAPI/#dfn-size
|
// https://w3c.github.io/FileAPI/#dfn-size
|
||||||
fn Size(&self) -> u64 {
|
fn Size(&self) -> u64 {
|
||||||
// XXX: This will incur reading if file-based
|
match *self.blob_impl.borrow() {
|
||||||
match self.get_bytes() {
|
BlobImpl::File(ref f) => f.size,
|
||||||
Ok(s) => s.len() as u64,
|
BlobImpl::Memory(ref v) => v.len() as u64,
|
||||||
_ => 0,
|
BlobImpl::Sliced(ref parent, ref rel_pos) =>
|
||||||
}
|
rel_pos.to_abs_range(parent.Size() as usize).len() as u64,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/FileAPI/#dfn-type
|
// https://w3c.github.io/FileAPI/#dfn-type
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue