From: Sergey Vladimirov Date: Mon, 25 Jul 2011 09:01:10 +0000 (+0000) Subject: compact similar CHPX after restoring bin table X-Git-Tag: REL_3_8_BETA4~84 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=405dd2f0019aaf38fc75d8c1ebcd3521b001605d;p=poi.git compact similar CHPX after restoring bin table git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1150595 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java index 3b2c7975ee..aed936329b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java @@ -20,10 +20,12 @@ package org.apache.poi.hwpf.model; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.IdentityHashMap; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -336,7 +338,35 @@ public class CHPBinTable logger.log( POILogger.DEBUG, "CHPX rebuilded in ", Long.valueOf( System.currentTimeMillis() - start ), " ms (", Integer.valueOf( _textRuns.size() ), " elements)" ); - } + start = System.currentTimeMillis(); + + CHPX previous = null; + for ( Iterator iterator = _textRuns.iterator(); iterator + .hasNext(); ) + { + CHPX current = iterator.next(); + if ( previous == null ) + { + previous = current; + continue; + } + + if ( previous.getEnd() == current.getStart() + && Arrays + .equals( previous.getGrpprl(), current.getGrpprl() ) ) + { + previous.setEnd( current.getEnd() ); + iterator.remove(); + continue; + } + + previous = current; + } + + logger.log( POILogger.DEBUG, "CHPX compacted in ", + Long.valueOf( System.currentTimeMillis() - start ), " ms (", + Integer.valueOf( _textRuns.size() ), " elements)" ); +} private static int binarySearch( List chpxs, int startPosition ) {