1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-26 07:03:22 +00:00

Use some sweet tricks to have a weak set to store open files

This commit is contained in:
Lignum 2017-05-05 19:11:59 +02:00
parent 06b63980eb
commit b0ac48b9a3
No known key found for this signature in database
GPG Key ID: 0889206F5A8A700D

View File

@ -11,7 +11,6 @@
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 @@ private String toLocal( String path )
}
private final Map<String, MountWrapper> m_mounts = new HashMap<String, MountWrapper>();
private final WeakHashMap<IMountedFile, Object> m_openFiles = new WeakHashMap<IMountedFile, Object>();
private final Set<IMountedFile> m_openFiles = Collections.newSetFromMap( new WeakHashMap<IMountedFile, Boolean>() );
public FileSystem( String rootLabel, IMount rootMount ) throws FileSystemException
{
@ -309,7 +308,7 @@ public void unload()
// Close all dangling open files
synchronized( m_openFiles )
{
for(IMountedFile file : m_openFiles.keySet())
for(IMountedFile file : m_openFiles)
{
try {
file.close();