]> source.dussan.org Git - poi.git/commitdiff
very small additional speed improvement (less garbage)
authorSergey Vladimirov <sergey@apache.org>
Mon, 18 Jul 2011 19:02:16 +0000 (19:02 +0000)
committerSergey Vladimirov <sergey@apache.org>
Mon, 18 Jul 2011 19:02:16 +0000 (19:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1148006 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java

index 53b92fcfaa7a81ce5863529fb0bb4418d98a364a..ea7d52a0be445149175acdd25bcee471b3ceb867 100644 (file)
@@ -48,7 +48,7 @@ public class PAPBinTable
 {
     private static final POILogger logger = POILogFactory
             .getLogger( PAPBinTable.class );
-    
+
   protected ArrayList<PAPX> _paragraphs = new ArrayList<PAPX>();
   byte[] _dataStream;
 
@@ -64,6 +64,7 @@ public class PAPBinTable
      *             {@link #PAPBinTable(byte[],byte[],byte[],int,int,int,TextPieceTable,boolean)}
      *             instead
      */
+    @SuppressWarnings( "unused" )
     public PAPBinTable( byte[] documentStream, byte[] tableStream,
             byte[] dataStream, int offset, int size, int fcMin,
             TextPieceTable tpt )
@@ -210,12 +211,21 @@ public class PAPBinTable
 
         final Map<PAPX, Integer> papxToFileOrder = new IdentityHashMap<PAPX, Integer>();
         {
-        int counter = 0;
-        for ( PAPX papx : _paragraphs )
-        {
-            papxToFileOrder.put( papx, Integer.valueOf( counter++ ) );
-        }
+            int counter = 0;
+            for ( PAPX papx : _paragraphs )
+            {
+                papxToFileOrder.put( papx, Integer.valueOf( counter++ ) );
+            }
         }
+        final Comparator<PAPX> papxFileOrderComparator = new Comparator<PAPX>()
+        {
+            public int compare( PAPX o1, PAPX o2 )
+            {
+                Integer i1 = papxToFileOrder.get( o1 );
+                Integer i2 = papxToFileOrder.get( o2 );
+                return i1.compareTo( i2 );
+            }
+        };
 
         logger.log( POILogger.DEBUG, "PAPX's order map created in ",
                 Long.valueOf( System.currentTimeMillis() - start ), " ms" );
@@ -277,15 +287,7 @@ public class PAPBinTable
             }
 
             // restore file order of PAPX
-            Collections.sort( papxs, new Comparator<PAPX>()
-            {
-                public int compare( PAPX o1, PAPX o2 )
-                {
-                    Integer i1 = papxToFileOrder.get( o1 );
-                    Integer i2 = papxToFileOrder.get( o2 );
-                    return i1.compareTo( i2 );
-                }
-            } );
+            Collections.sort( papxs, papxFileOrderComparator );
 
             SprmBuffer sprmBuffer = null;
             for ( PAPX papx : papxs )
@@ -312,6 +314,10 @@ public class PAPBinTable
         }
         this._paragraphs = new ArrayList<PAPX>( newPapxs );
 
+        logger.log( POILogger.DEBUG, "PAPX rebuilded from document text in ",
+                Long.valueOf( System.currentTimeMillis() - start ), " ms" );
+        start = System.currentTimeMillis();
+
         _dataStream = dataStream;
     }