-------------This email and the patch follow the provisions of GPL 3. hi,i modified the code of libreoffice to access the file in disk,mainly in sot module and the speed for libreoffice to open a ppt file from disk is 25% faster. My computer : cpu:unicore-2 600Mhz,mem:1GB.DDR2 The main change: I found that when libreoffice reads a byte from the file,it will traverse the list of sectors and it is slow.So i use an array to save the list.when reading a byte,we can use the array to obtain the address of this byte in disk directly.This change wil accelerate the process of opening a ppt file from disk.Theorily,it also can improve the perfommance of libreoffice running ,but if the file is changed ,the array will be failed。Therefore,i add an tag to mark whether the file is modified.If it is changed,we can use the list,else we use the array. The patch :
diff -u orig/sot/source/sdstor/stgdir.cxx optimized/sot/source/sdstor/stgdir.cxx --- orig/sot/source/sdstor/stgdir.cxx 2010-07-23 11:31:38.046198867 +0800 +++ optimized/sot/source/sdstor/stgdir.cxx 2011-03-12 12:30:07.092985044 +0800 @@ -879,6 +879,7 @@ BOOL StgDirStrm::Store() { + Dirty=true; if( !pRoot->IsDirty() ) return TRUE; if( !pRoot->StoreStreams( rIo ) ) diff -u orig/sot/source/sdstor/stgstrms.cxx optimized/sot/source/sdstor/stgstrms.cxx --- orig/sot/source/sdstor/stgstrms.cxx 2010-07-23 11:31:38.046198867 +0800 +++ optimized/sot/source/sdstor/stgstrms.cxx 2011-03-12 12:41:12.756986414 +0800 @@ -327,6 +327,8 @@ pEntry = NULL; nPos = nSize = 0; nPageSize = rIo.GetPhysPageSize(); + initFAT=true; + Dirty=false; } StgStrm::~StgStrm() @@ -350,6 +352,32 @@ BOOL StgStrm::Pos2Page( INT32 nBytePos ) { + if(initFAT==true) + { + initFAT=false; + + FAT[0]=nStart; + for(INT32 i=1;i<8192;i++) + FAT[i]=-5; + + INT32 nRel,nBgn,currentSuffix; + currentSuffix=0; + nRel=nSize/nPageSize; + if(nRel==0) + FAT[++currentSuffix]=-2; + else + { + nBgn=nStart; + + while(nRel && nBgn>=0) + { + nBgn=pFat->GetNextPage(nBgn); + FAT[++currentSuffix]=nBgn; + nRel--; + } + } + + } INT32 nRel, nBgn; // Values < 0 seek to the end if( nBytePos < 0 || nBytePos >= nSize ) @@ -363,7 +391,29 @@ nPos = nBytePos; if( nOld == nNew ) return TRUE; - if( nNew > nOld ) + if(Dirty==false) + { + INT32 nDestPage=nNew/nPageSize; + INT32 nNewPage=FAT[nDestPage]; + + if(nNewPage!=-5) + { + nPage=nNewPage; + if(nBytePos==nSize&&!nOffset) + { + nPage=FAT[nDestPage-1]; + nOffset=nPageSize; + } + return BOOL(nPage>=0); + } + else + { + rIo.SetError( SVSTREAM_FILEFORMAT_ERROR ); + nPage = STG_EOF; + nOffset = nPageSize; + } + } + if( nNew >= nOld ) { // the new position is behind the current, so an incremental // positioning is OK. Set the page relative position @@ -879,6 +929,7 @@ INT32 StgDataStrm::Write( const void* pBuf, INT32 n ) { + Dirty=true; INT32 nDone = 0; if( ( nPos + n ) > nSize ) { @@ -1005,6 +1056,7 @@ INT32 StgSmallStrm::Write( const void* pBuf, INT32 n ) { + Dirty=true; // you can safely assume that reads are not huge, since the // small stream is likely to be < 64 KBytes. short nDone = 0; diff -u orig/sot/source/sdstor/stgstrms.hxx optimized/sot/source/sdstor/stgstrms.hxx --- orig/sot/source/sdstor/stgstrms.hxx 2011-03-12 12:37:52.468985102 +0800 +++ optimized/sot/source/sdstor/stgstrms.hxx 2011-03-12 12:37:49.297042325 +0800 @@ -84,6 +84,9 @@ BOOL Copy( INT32 nFrom, INT32 nBytes ); StgStrm( StgIo& ); public: + INT32 FAT[8192]; + BOOL initFAT; + BOOL Dirty; virtual ~StgStrm(); StgIo& GetIo() { return rIo; } INT32 GetPos() { return nPos; } @@ -97,7 +100,7 @@ virtual BOOL SetSize( INT32 ); virtual BOOL Pos2Page( INT32 nBytePos ); virtual INT32 Read( void*, INT32 ) { return 0; } - virtual INT32 Write( const void*, INT32 ) { return 0; } + virtual INT32 Write( const void*, INT32 ) { Dirty=true; return 0; } virtual StgPage* GetPhysPage( INT32 nBytePos, BOOL bForce = FALSE ); virtual BOOL IsSmallStrm() { return FALSE; } }; -- Shantong Kang 康善同 Microprocessor R&D Center(MPRC) Room 1818,Science Building 1, Peking University, Beijing, P.R.China, 100871 Tel: 86-010-62763734 Mobile: 86-15210037972
_______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice