mirror of https://github.com/apache/poi.git
Improve the speed of the styles-optimiser when there are many styles in a Workbook
Profiling showed that the call to isUserDefined() took most of the time, so we now fetch this only once for each style and remember the result and use it in the inner loop. The attached sample-file took aprox. 1m30s on a decent machine, now it is down to around 2s. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884917 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b7463df98c
commit
a7c1d84c5d
|
@ -178,17 +178,24 @@ public class HSSFOptimiser {
|
|||
short[] newPos = new short[workbook.getWorkbook().getNumExFormats()];
|
||||
boolean[] isUsed = new boolean[newPos.length];
|
||||
boolean[] zapRecords = new boolean[newPos.length];
|
||||
|
||||
// to speed up the optimisation for workbooks with a large number of
|
||||
// styles we perform the isUserDefined() check only once as it is
|
||||
// costly according to some profiling
|
||||
boolean[] userDefined = new boolean[newPos.length];
|
||||
|
||||
// Get each style record, so we can do deletes
|
||||
// without getting confused
|
||||
ExtendedFormatRecord[] xfrs = new ExtendedFormatRecord[newPos.length];
|
||||
|
||||
for(int i=0; i<newPos.length; i++) {
|
||||
isUsed[i] = false;
|
||||
newPos[i] = (short)i;
|
||||
zapRecords[i] = false;
|
||||
}
|
||||
|
||||
// Get each style record, so we can do deletes
|
||||
// without getting confused
|
||||
ExtendedFormatRecord[] xfrs = new ExtendedFormatRecord[newPos.length];
|
||||
for(int i=0; i<newPos.length; i++) {
|
||||
xfrs[i] = workbook.getWorkbook().getExFormatAt(i);
|
||||
userDefined[i] = isUserDefined(workbook, i);
|
||||
|
||||
xfrs[i] = workbook.getWorkbook().getExFormatAt(i);
|
||||
}
|
||||
|
||||
// Loop over each style, seeing if it is the same
|
||||
|
@ -200,12 +207,13 @@ public class HSSFOptimiser {
|
|||
// Check this one for being a duplicate
|
||||
// of an earlier one
|
||||
int earlierDuplicate = -1;
|
||||
for (int j = 0; j < i && earlierDuplicate == -1; j++) {
|
||||
for (int j = 0; j < i; j++) {
|
||||
ExtendedFormatRecord xfCheck = workbook.getWorkbook().getExFormatAt(j);
|
||||
if (xfCheck.equals(xfrs[i]) &&
|
||||
// newer duplicate user defined styles
|
||||
!isUserDefined(workbook, j)) {
|
||||
// never duplicate user defined styles
|
||||
!userDefined[j]) {
|
||||
earlierDuplicate = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue