[PATCH] Resolves: fdo#47644 compound storage backend is poor at knowing stream size

Caolán McNamara caolanm at redhat.com
Thu May 10 07:41:17 PDT 2012


---
 sot/inc/sot/stg.hxx              |    3 +++
 sot/inc/sot/storage.hxx          |    1 +
 sot/source/sdstor/stg.cxx        |    7 +++++++
 sot/source/sdstor/storage.cxx    |    7 +++++++
 sot/source/sdstor/ucbstorage.cxx |    5 +++++
 tools/inc/tools/stream.hxx       |    3 ++-
 tools/source/stream/stream.cxx   |    6 +++---
 7 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/sot/inc/sot/stg.hxx b/sot/inc/sot/stg.hxx
index c8d18da..3071017 100644
--- a/sot/inc/sot/stg.hxx
+++ b/sot/inc/sot/stg.hxx
@@ -90,6 +90,7 @@ public:
     virtual sal_uLong   Tell() = 0;
     virtual void    Flush() = 0;
     virtual sal_Bool    SetSize( sal_uLong nNewSize ) = 0;
+    virtual sal_uLong   GetSize() const = 0;
     virtual sal_Bool    CopyTo( BaseStorageStream * pDestStm ) = 0;
     virtual sal_Bool    Commit() = 0;
     virtual sal_Bool    Revert() = 0;
@@ -171,6 +172,7 @@ public:
     virtual sal_uLong   Tell() { return nPos; }
     virtual void    Flush();
     virtual sal_Bool    SetSize( sal_uLong nNewSize );
+    virtual sal_uLong   GetSize() const;
     virtual sal_Bool    CopyTo( BaseStorageStream * pDestStm );
     virtual sal_Bool    Commit();
     virtual sal_Bool    Revert();
@@ -266,6 +268,7 @@ public:
     virtual sal_uLong               Tell();
     virtual void                Flush();
     virtual sal_Bool                SetSize( sal_uLong nNewSize );
+    virtual sal_uLong               GetSize() const;
     virtual sal_Bool                CopyTo( BaseStorageStream * pDestStm );
     virtual sal_Bool                Commit();
     virtual sal_Bool                Revert();
diff --git a/sot/inc/sot/storage.hxx b/sot/inc/sot/storage.hxx
index 26258bc..4f602e9 100644
--- a/sot/inc/sot/storage.hxx
+++ b/sot/inc/sot/storage.hxx
@@ -96,6 +96,7 @@ public:
     sal_Bool                GetProperty( const String& rName, ::com::sun::star::uno::Any& rValue );
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
                         GetXInputStream() const;
+    virtual sal_Size remainingSize();
 };
 
 #ifndef SOT_DECL_SOTSTORAGESTREAM_DEFINED
diff --git a/sot/source/sdstor/stg.cxx b/sot/source/sdstor/stg.cxx
index 4c4be65..18e95f6 100644
--- a/sot/source/sdstor/stg.cxx
+++ b/sot/source/sdstor/stg.cxx
@@ -252,6 +252,13 @@ sal_Bool StorageStream::SetSize( sal_uLong nNewSize )
         return sal_False;
 }
 
+sal_uLong StorageStream::GetSize() const
+{
+    if( Validate() )
+        return pEntry->GetSize();
+    return 0;
+}
+
 sal_Bool StorageStream::Commit()
 {
     if( !Validate() )
diff --git a/sot/source/sdstor/storage.cxx b/sot/source/sdstor/storage.cxx
index 897f9fe..4d24f1f 100644
--- a/sot/source/sdstor/storage.cxx
+++ b/sot/source/sdstor/storage.cxx
@@ -298,6 +298,13 @@ sal_uInt32 SotStorageStream::GetSize() const
     return nSize;
 }
 
+sal_Size SotStorageStream::remainingSize()
+{
+    if (pOwnStm)
+        return pOwnStm->GetSize() - Tell();
+    return SvStream::remainingSize();
+}
+
 /*************************************************************************
 |*    SotStorageStream::CopyTo()
 |*
diff --git a/sot/source/sdstor/ucbstorage.cxx b/sot/source/sdstor/ucbstorage.cxx
index b6fb581..020fb9a 100644
--- a/sot/source/sdstor/ucbstorage.cxx
+++ b/sot/source/sdstor/ucbstorage.cxx
@@ -1566,6 +1566,11 @@ sal_Bool UCBStorageStream::GetProperty( const String& rName, ::com::sun::star::u
     return sal_False;
 }
 
+sal_uLong UCBStorageStream::GetSize() const
+{
+    return pImp->GetSize();
+}
+
 UCBStorage::UCBStorage( SvStream& rStrm, sal_Bool bDirect )
 {
     String aURL = GetLinkedFile( rStrm );
diff --git a/tools/inc/tools/stream.hxx b/tools/inc/tools/stream.hxx
index 0ad9585..e577ca8 100644
--- a/tools/inc/tools/stream.hxx
+++ b/tools/inc/tools/stream.hxx
@@ -379,7 +379,7 @@ public:
     sal_Size        SeekRel( sal_sSize nPos );
     sal_Size        Tell() const { return nBufFilePos+nBufActualPos;  }
     //length between current (Tell()) pos and end of stream
-    sal_Size        remainingSize();
+    virtual sal_Size remainingSize();
     void            Flush();
     sal_Bool        IsEof() const { return bIsEof; }
     // next Tell() <= nSize
@@ -678,6 +678,7 @@ public:
     sal_Bool            IsObjectMemoryOwner() { return bOwnsData; }
     void            SetResizeOffset( sal_Size nNewResize ) { nResize = nNewResize; }
     sal_Size            GetResizeOffset() const { return nResize; }
+    virtual sal_Size remainingSize() { return GetSize() - Tell(); }
 };
 
 // --------------------
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index 3e870b4..84d652c 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -1820,9 +1820,9 @@ sal_Size SvStream::Seek( sal_Size nFilePos )
     return nBufFilePos + nBufActualPos;
 }
 
-//probably not as inefficient as it looks seeing as STREAM_SEEK_TO_END in the
-//Seek backends is nomally special cased feel free to make this virtual and add
-//good implementations for SvFileStream etc
+//STREAM_SEEK_TO_END in the some of the Seek backends is special cased to be
+//efficient, in others e.g. SotStorageStream it's really horribly slow, and in
+//those this should be overridden
 sal_Size SvStream::remainingSize()
 {
     sal_Size nCurr = Tell();
-- 
1.7.7.6


--=-r6tz3jYvke2/iB3cGwd0
Content-Disposition: attachment;
	filename*0=0001-Related-fdo-47644-for-huge-files-build-a-page-chain-.pat;
	filename*1=ch
Content-Type: text/x-patch;
	name="0001-Related-fdo-47644-for-huge-files-build-a-page-chain-.patch";
	charset="UTF-8"
Content-Transfer-Encoding: 7bit



More information about the LibreOffice mailing list