[github-735] POIFS: optimise occupied size calc. Thanks to Emmanuel Bourg. This closes #735

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1922232 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2024-11-30 10:47:53 +00:00
parent 1700967d17
commit c57f7a3b0e
2 changed files with 6 additions and 10 deletions

View File

@ -266,10 +266,9 @@ public class POIFSMiniStore extends BlockStore {
int entriesPerBlock = _filesystem.getBigBlockSizeDetails().getBATEntriesPerBlock();
for (int sbatIndex = _sbat_blocks.size() - 1; sbatIndex >= 0; sbatIndex--) {
BATBlock sbat = _sbat_blocks.get(sbatIndex);
for (int miniBlockIndex = entriesPerBlock - 1; miniBlockIndex >= 0; miniBlockIndex--) {
if (sbat.getValueAt(miniBlockIndex) != POIFSConstants.UNUSED_BLOCK) {
return (sbatIndex * entriesPerBlock) + miniBlockIndex + 1;
}
int occupiedSize = sbat.getOccupiedSize();
if (occupiedSize > 0) {
return (sbatIndex * entriesPerBlock) + occupiedSize;
}
}

View File

@ -202,15 +202,12 @@ public final class BATBlock implements BlockWritable {
* @since POI 5.0.0
*/
public int getOccupiedSize() {
int usedSectors = _values.length;
for (int k = _values.length - 1; k >= 0; k--) {
if(_values[k] == POIFSConstants.UNUSED_BLOCK) {
usedSectors--;
} else {
break;
if (_values[k] != POIFSConstants.UNUSED_BLOCK) {
return k + 1;
}
}
return usedSectors;
return 0;
}
public int getValueAt(int relativeOffset) {