You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2021/05/22 15:29:23 UTC
[commons-compress] 01/02: tiny performance improvement
This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 6a72242a7b6089cad8f35eac21785399f29d8a8c
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Sat May 22 17:14:02 2021 +0200
tiny performance improvement
---
.../org/apache/commons/compress/archivers/tar/TarArchiveEntry.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
index 158c1d2..ff10db2 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
@@ -947,9 +947,10 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants, EntryStreamO
.sorted(Comparator.comparingLong(TarArchiveStructSparse::getOffset))
.collect(Collectors.toList());
- for (int i = 0; i < orderedAndFiltered.size(); i++) {
+ final int numberOfHeaders = orderedAndFiltered.size();
+ for (int i = 0; i < numberOfHeaders; i++) {
final TarArchiveStructSparse str = orderedAndFiltered.get(i);
- if (i + 1 < orderedAndFiltered.size()) {
+ if (i + 1 < numberOfHeaders) {
if (str.getOffset() + str.getNumbytes() > orderedAndFiltered.get(i + 1).getOffset()) {
throw new IOException("Corrupted TAR archive. Sparse blocks for "
+ getName() + " overlap each other.");
@@ -962,7 +963,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants, EntryStreamO
}
}
if (!orderedAndFiltered.isEmpty()) {
- final TarArchiveStructSparse last = orderedAndFiltered.get(orderedAndFiltered.size() - 1);
+ final TarArchiveStructSparse last = orderedAndFiltered.get(numberOfHeaders - 1);
if (last.getOffset() + last.getNumbytes() > getRealSize()) {
throw new IOException("Corrupted TAR archive. Sparse block extends beyond real size of the entry");
}