From db7e2c72f609c4988676ac534f9181e7ad21358e Mon Sep 17 00:00:00 2001 From: Nikolas Havrikov Date: Wed, 23 Feb 2022 16:17:13 +0100 Subject: [PATCH] Replace LinkedList by a more performant collection This is a semi-automatic change. See go/bugpattern/JdkObsolete#linkedlist for the rationale Test: make Bug: 221046110 Change-Id: Ic36738ad7159f759da330ae90441644bbba7ee2c --- .../android/internal/content/FileSystemProvider.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/java/com/android/internal/content/FileSystemProvider.java b/core/java/com/android/internal/content/FileSystemProvider.java index a60b31078a864..73a4f1c4a154a 100644 --- a/core/java/com/android/internal/content/FileSystemProvider.java +++ b/core/java/com/android/internal/content/FileSystemProvider.java @@ -62,7 +62,9 @@ import java.nio.file.FileVisitor; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Deque; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -232,9 +234,9 @@ public abstract class FileSystemProvider extends DocumentsProvider { throw new FileNotFoundException(doc + " is not found under " + parent); } - LinkedList path = new LinkedList<>(); + List path = new ArrayList<>(); while (doc != null && FileUtils.contains(parent, doc)) { - path.addFirst(getDocIdForFile(doc)); + path.add(0, getDocIdForFile(doc)); doc = doc.getParentFile(); } @@ -448,10 +450,10 @@ public abstract class FileSystemProvider extends DocumentsProvider { File folder, String[] projection, Set exclusion, Bundle queryArgs) throws FileNotFoundException { final MatrixCursor result = new MatrixCursor(resolveProjection(projection)); - final LinkedList pending = new LinkedList<>(); + final List pending = new ArrayList<>(); pending.add(folder); while (!pending.isEmpty() && result.getCount() < 24) { - final File file = pending.removeFirst(); + final File file = pending.remove(0); if (shouldHide(file)) continue; if (file.isDirectory()) {