You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/10/26 14:41:32 UTC
[commons-compress] 04/04: Precompile regular expression in ChangeSet.addDeletion(Change)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit e2f64df6e52908ab7a8f2118bf286d5d29483eb6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Oct 26 10:41:21 2023 -0400
Precompile regular expression in ChangeSet.addDeletion(Change)
---
src/changes/changes.xml | 1 +
.../java/org/apache/commons/compress/changes/ChangeSet.java | 13 +++++--------
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c4f7565e..62bb98a4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -67,6 +67,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regualr expression in ArArchiveInputStream.isBSDLongName(String).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regular expression in ArArchiveInputStream.isGNULongName(String).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regular expression in TarArchiveEntry.parseInstantFromDecimalSeconds(String).</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regular expression in ChangeSet.addDeletion(Change).</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot">Bump org.slf4j:slf4j-api from 2.0.8 to 2.0.9 #413.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump commons-io:commons-io from 2.13.0 to 2.15.0.</action>
diff --git a/src/main/java/org/apache/commons/compress/changes/ChangeSet.java b/src/main/java/org/apache/commons/compress/changes/ChangeSet.java
index e99cb093..e1586690 100644
--- a/src/main/java/org/apache/commons/compress/changes/ChangeSet.java
+++ b/src/main/java/org/apache/commons/compress/changes/ChangeSet.java
@@ -22,6 +22,7 @@ import java.io.InputStream;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
+import java.util.regex.Pattern;
import org.apache.commons.compress.archivers.ArchiveEntry;
@@ -71,16 +72,14 @@ public final class ChangeSet {
* the change which should result in an addition
*/
private void addAddition(final Change pChange) {
- if (Change.TYPE_ADD != pChange.type() ||
- pChange.getInput() == null) {
+ if (Change.TYPE_ADD != pChange.type() || pChange.getInput() == null) {
return;
}
if (!changes.isEmpty()) {
for (final Iterator<Change> it = changes.iterator(); it.hasNext();) {
final Change change = it.next();
- if (change.type() == Change.TYPE_ADD
- && change.getEntry() != null) {
+ if (change.type() == Change.TYPE_ADD && change.getEntry() != null) {
final ArchiveEntry entry = change.getEntry();
if (entry.equals(pChange.getEntry())) {
@@ -110,20 +109,18 @@ public final class ChangeSet {
return;
}
final String source = pChange.targetFile();
-
+ final Pattern pattern = Pattern.compile(source + "/.*");
if (source != null && !changes.isEmpty()) {
for (final Iterator<Change> it = changes.iterator(); it.hasNext();) {
final Change change = it.next();
if (change.type() == Change.TYPE_ADD
&& change.getEntry() != null) {
final String target = change.getEntry().getName();
-
if (target == null) {
continue;
}
-
if (Change.TYPE_DELETE == pChange.type() && source.equals(target) ||
- Change.TYPE_DELETE_DIR == pChange.type() && target.matches(source + "/.*")) {
+ Change.TYPE_DELETE_DIR == pChange.type() && pattern.matcher(target).matches()) {
it.remove();
}
}