Skip to content

Commit

Permalink
[github-735] POIFS: optimise occupied size calc. Thanks to Emmanuel B…
Browse files Browse the repository at this point in the history
…ourg. This closes #735

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1922232 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed Nov 30, 2024
1 parent 1700967 commit c57f7a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,9 @@ private int computeSize() {
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;
}
}

Expand Down
9 changes: 3 additions & 6 deletions poi/src/main/java/org/apache/poi/poifs/storage/BATBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,12 @@ public int getUsedSectors(boolean isAnXBAT) {
* @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) {
Expand Down

0 comments on commit c57f7a3

Please sign in to comment.