From b0ac48b9a3bc81ecf487ec64edc396a05de3afae Mon Sep 17 00:00:00 2001 From: Lignum Date: Fri, 5 May 2017 19:11:59 +0200 Subject: [PATCH] Use some sweet tricks to have a weak set to store open files --- .../dan200/computercraft/core/filesystem/FileSystem.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 71344f562..cca6a01a2 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -11,7 +11,6 @@ import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IWritableMount; import java.io.*; -import java.lang.ref.WeakReference; import java.util.*; import java.util.regex.Pattern; @@ -292,7 +291,7 @@ public class FileSystem } private final Map m_mounts = new HashMap(); - private final WeakHashMap m_openFiles = new WeakHashMap(); + private final Set m_openFiles = Collections.newSetFromMap( new WeakHashMap() ); public FileSystem( String rootLabel, IMount rootMount ) throws FileSystemException { @@ -309,7 +308,7 @@ public class FileSystem // Close all dangling open files synchronized( m_openFiles ) { - for(IMountedFile file : m_openFiles.keySet()) + for(IMountedFile file : m_openFiles) { try { file.close();