Skip to content

Commit

Permalink
Improve Blob.Size() speed by avoid reading content
Browse files Browse the repository at this point in the history
  • Loading branch information
izgzhen committed Aug 16, 2016
1 parent 49431be commit 06e29c0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions components/script/dom/blob.rs
Expand Up @@ -357,11 +357,12 @@ pub fn blob_parts_to_bytes(blobparts: Vec<BlobOrString>) -> Result<Vec<u8>, ()>
impl BlobMethods for Blob {
// https://w3c.github.io/FileAPI/#dfn-size
fn Size(&self) -> u64 {
// XXX: This will incur reading if file-based
match self.get_bytes() {
Ok(s) => s.len() as u64,
_ => 0,
}
match *self.blob_impl.borrow() {
BlobImpl::File(ref f) => f.size,
BlobImpl::Memory(ref v) => v.len() as u64,
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
Expand Down

0 comments on commit 06e29c0

Please sign in to comment.