From ec0657ba014585261d3c3c4d69cb905216c5efb5 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Sat, 16 Sep 2023 22:33:17 +0200 Subject: [errorprone] Use ArrayList instead of LinkedList [JdkObsolete] It is very rare for LinkedList to out-perform ArrayList or ArrayDeque. see https://errorprone.info/bugpattern/JdkObsolete Change-Id: I13fb953f55fc7b6e007d6fd6a6a1bfd377773588 --- org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java | 4 ++-- .../src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java | 12 +++++++----- org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java index abad766e40..c895dc9aaa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java @@ -18,7 +18,7 @@ import static org.eclipse.jgit.lib.FileMode.TYPE_TREE; import java.io.IOException; import java.io.InputStream; import java.time.Instant; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.eclipse.jgit.api.errors.FilterFailedException; @@ -73,7 +73,7 @@ public class AddCommand extends GitCommand { */ public AddCommand(Repository repo) { super(repo); - filepatterns = new LinkedList<>(); + filepatterns = new ArrayList<>(); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java index b2242a11ca..5dfb648faa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java @@ -24,8 +24,8 @@ import static org.eclipse.jgit.lib.Constants.GIT_WORK_TREE_KEY; import java.io.File; import java.io.IOException; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.eclipse.jgit.annotations.NonNull; @@ -205,8 +205,9 @@ public class BaseRepositoryBuilder(); + if (alternateObjectDirectories == null) { + alternateObjectDirectories = new ArrayList<>(); + } alternateObjectDirectories.add(other); } return self(); @@ -473,8 +474,9 @@ public class BaseRepositoryBuilder(); + if (ceilingDirectories == null) { + ceilingDirectories = new ArrayList<>(); + } ceilingDirectories.add(root); } return self(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index d446a1c9c7..4722e29b4c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -15,8 +15,8 @@ package org.eclipse.jgit.lib; -import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; import java.io.BufferedOutputStream; import java.io.File; @@ -27,11 +27,11 @@ import java.io.OutputStream; import java.io.UncheckedIOException; import java.net.URISyntaxException; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -1815,7 +1815,7 @@ public abstract class Repository implements AutoCloseable { if (raw == null) return null; - LinkedList heads = new LinkedList<>(); + List heads = new ArrayList<>(); for (int p = 0; p < raw.length;) { heads.add(ObjectId.fromString(raw, p)); p = RawParseUtils -- cgit v1.2.3