From 06e29c0497459ec211ed809bd593c831649f817f Mon Sep 17 00:00:00 2001 From: Zhen Zhang Date: Tue, 16 Aug 2016 23:17:54 +0200 Subject: [PATCH] Improve Blob.Size() speed by avoid reading content --- components/script/dom/blob.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs index 4711da800108..11f323af6bef 100644 --- a/components/script/dom/blob.rs +++ b/components/script/dom/blob.rs @@ -357,11 +357,12 @@ pub fn blob_parts_to_bytes(blobparts: Vec) -> Result, ()> 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