From 624ad2e6d3c68f1806cd8969092406a2d3469034 Mon Sep 17 00:00:00 2001 From: Pinghao Wu Date: Sat, 2 Nov 2024 19:15:16 +0800 Subject: [PATCH] CephFSDocumentsProvider: use HashSet for thumbnail lookup --- .../safcephfs/CephFSDocumentsProvider.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/safcephfs/CephFSDocumentsProvider.java b/src/main/java/org/safcephfs/CephFSDocumentsProvider.java index 6c1bb9f..107ef9c 100644 --- a/src/main/java/org/safcephfs/CephFSDocumentsProvider.java +++ b/src/main/java/org/safcephfs/CephFSDocumentsProvider.java @@ -34,7 +34,10 @@ import java.io.IOException; import java.io.UncheckedIOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; import com.ceph.fs.CephMount; import com.ceph.fs.CephStat; @@ -319,7 +322,7 @@ public class CephFSDocumentsProvider extends DocumentsProvider { } private void buildDocumentRow(String dir, String displayName, - MatrixCursor result, String[] thumbnails, CephStat parentStat) + MatrixCursor result, Set thumbnails, CephStat parentStat) throws FileNotFoundException { // TODO consider EXTRA_ERROR? var path = dir + displayName; @@ -386,13 +389,7 @@ public class CephFSDocumentsProvider extends DocumentsProvider { String thumbnail = getXDGThumbnailFile(displayName); boolean thumbnailFound = false; if (thumbnails != null) { - // TODO pre-sort & bsearch? - for (String c : thumbnails) { - if (c.equals(thumbnail)) { - thumbnailFound = true; - break; - } - } + thumbnailFound = thumbnails.contains(thumbnail); } else { String thubmailPath = dir + ".sh_thumbnails/normal/" + getXDGThumbnailFile(displayName); var ncs = new CephStat(); @@ -479,15 +476,15 @@ public class CephFSDocumentsProvider extends DocumentsProvider { return result; } - String[] thumbnails = null; + Set thumbnails = null; try { - thumbnails = executor.execute(cm -> { + thumbnails = new HashSet(Arrays.asList(executor.execute(cm -> { try { return cm.listdir(path + "/.sh_thumbnails/normal"); } catch (FileNotFoundException e) { return new String[0]; } - }); + }))); } catch (IOException e) { Log.w("Fail to list thumbnails directory, falling back to per-file slow path", e); } -- 2.45.2