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 2022/12/01 15:11:38 UTC

[commons-vfs] branch master updated: Lookup key in map only once

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-vfs.git


The following commit(s) were added to refs/heads/master by this push:
     new d1cd9e2a Lookup key in map only once
d1cd9e2a is described below

commit d1cd9e2a4f44f41a07b8db4634a41cf5965c913b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Dec 1 10:11:32 2022 -0500

    Lookup key in map only once
    
    Use Java Map API better
---
 .../main/java/org/apache/commons/vfs2/cache/SoftRefFilesCache.java | 3 ++-
 .../org/apache/commons/vfs2/impl/DefaultFileSystemManager.java     | 7 +------
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/cache/SoftRefFilesCache.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/cache/SoftRefFilesCache.java
index 78a4705c..31404641 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/cache/SoftRefFilesCache.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/cache/SoftRefFilesCache.java
@@ -190,7 +190,8 @@ public class SoftRefFilesCache extends AbstractFilesCache {
             final Reference<FileObject> ref = createReference(fileObject, refQueue);
             final FileSystemAndNameKey key = new FileSystemAndNameKey(fileObject.getFileSystem(), fileObject.getName());
 
-            if (files.containsKey(fileObject.getName()) && files.get(fileObject.getName()).get() != null) {
+            final Reference<FileObject> reference = files.get(fileObject.getName());
+            if (reference != null && reference.get() != null) {
                 return false;
             }
             final Reference<FileObject> old = files.put(fileObject.getName(), ref);
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java
index 800588cc..b7d87572 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java
@@ -238,12 +238,7 @@ public class DefaultFileSystemManager implements FileSystemManager {
     public void addOperationProvider(final String[] schemes, final FileOperationProvider operationProvider)
             throws FileSystemException {
         for (final String scheme : schemes) {
-            if (!operationProviders.containsKey(scheme)) {
-                final List<FileOperationProvider> providers = new ArrayList<>();
-                operationProviders.put(scheme, providers);
-            }
-
-            final List<FileOperationProvider> providers = operationProviders.get(scheme);
+            final List<FileOperationProvider> providers = operationProviders.computeIfAbsent(scheme, k -> new ArrayList<>());
 
             if (providers.contains(operationProvider)) {
                 throw new FileSystemException("vfs.operation/operation-provider-already-added.error", scheme);