aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2024-11-30 10:47:53 +0000
committerPJ Fanning <fanningpj@apache.org>2024-11-30 10:47:53 +0000
commitc57f7a3b0e03cff00ebeda8999d00bb9094a0d1f (patch)
treeefe7a62f830791232d5af8b7502c8fcd0a60171a /poi
parent1700967d1783a65ed99cf60ba4212756cce5a288 (diff)
downloadpoi-c57f7a3b0e03cff00ebeda8999d00bb9094a0d1f.tar.gz
poi-c57f7a3b0e03cff00ebeda8999d00bb9094a0d1f.zip
[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
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSMiniStore.java7
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/storage/BATBlock.java9
2 files changed, 6 insertions, 10 deletions
diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSMiniStore.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSMiniStore.java
index cb1929d0d6..5274361649 100644
--- a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSMiniStore.java
+++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSMiniStore.java
@@ -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;
}
}
diff --git a/poi/src/main/java/org/apache/poi/poifs/storage/BATBlock.java b/poi/src/main/java/org/apache/poi/poifs/storage/BATBlock.java
index 33bea9936a..766958ab20 100644
--- a/poi/src/main/java/org/apache/poi/poifs/storage/BATBlock.java
+++ b/poi/src/main/java/org/apache/poi/poifs/storage/BATBlock.java
@@ -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) {