<div class="gmail_quote"><div class="gmail_quote">-------------This email and the patch follow <font class="Apple-style-span" size="1">&nbsp;<span class="Apple-style-span" style="font-family: arial, sans-serif; "><span class="hps" title="点击可显示其他翻译">the provisions of</span>&nbsp;<span class="hps" title="点击可显示其他翻译">GPL 3.</span></span></font></div>
<div class="gmail_quote">hi,i modified the code of libreoffice to access the file in disk,mainly in sot module and the speed for&nbsp;libreoffice&nbsp;&nbsp;to open a ppt file from disk is 25% faster.<br>My computer :<br>&nbsp;&nbsp; cpu:unicore-2 600Mhz,mem:1GB.DDR2<br>


The main change:<br>
&nbsp;&nbsp; I found that when&nbsp;libreoffice&nbsp;&nbsp;reads a byte from the file,it will <span lang="en"><span title="">traverse the list</span></span>&nbsp; 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&nbsp; the process of opening a ppt file from disk.Theorily,it also can improve the perfommance of&nbsp;libreoffice&nbsp;&nbsp;running ,but if the file is&nbsp; 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.</div>


<div class="gmail_quote">
The patch :<span class="Apple-style-span" style="font-family: Simsun; font-size: medium; "><pre style="word-wrap: break-word; white-space: pre-wrap; ">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-&gt;IsDirty() )
         return TRUE;
     if( !pRoot-&gt;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&lt;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 &amp;&amp; nBgn&gt;=0)
+                        {
+                                nBgn=pFat-&gt;GetNextPage(nBgn);
+                                FAT[++currentSuffix]=nBgn;
+                                nRel--;
+                        }
+                }
+        
+        }
     INT32 nRel, nBgn;
     // Values &lt; 0 seek to the end
     if( nBytePos &lt; 0 || nBytePos &gt;= nSize )
@@ -363,7 +391,29 @@
     nPos = nBytePos;
     if( nOld == nNew )
         return TRUE;
-    if( nNew &gt; nOld )
+    if(Dirty==false)
+        {
+                INT32 nDestPage=nNew/nPageSize;
+                INT32 nNewPage=FAT[nDestPage];
+        
+                if(nNewPage!=-5)
+                {
+                        nPage=nNewPage;
+                        if(nBytePos==nSize&amp;&amp;!nOffset)
+                        {
+                                nPage=FAT[nDestPage-1];
+                                nOffset=nPageSize;
+                        }
+                        return BOOL(nPage&gt;=0);
+                }
+                else
+                {
+                           rIo.SetError( SVSTREAM_FILEFORMAT_ERROR );
+                           nPage = STG_EOF;
+                        nOffset = nPageSize;
+                }
+        }
+    if( nNew &gt;= 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 ) &gt; 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 &lt; 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&amp; );
 public:
+        INT32 FAT[8192];
+        BOOL  initFAT;
+        BOOL  Dirty;
     virtual ~StgStrm();
     StgIo&amp;  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; }
 };</pre></span></div></div>-- <br>Shantong Kang&nbsp; &nbsp;&nbsp; 康善同<br>Microprocessor R&amp;D Center(MPRC)<br>Room 1818,Science Building 1,<br>Peking University,<br>Beijing, P.R.China, 100871<br>Tel: 86-010-62763734<br>Mobile: 86-15210037972<br>