mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-30 17:17:55 +00:00
Merge pull request #200 from Lignum/fs-weak-set
Replace WeakHashMap for open files with a weak set
This commit is contained in:
@@ -11,7 +11,6 @@ import dan200.computercraft.api.filesystem.IMount;
|
|||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -292,7 +291,7 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final Map<String, MountWrapper> m_mounts = new HashMap<String, MountWrapper>();
|
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
|
public FileSystem( String rootLabel, IMount rootMount ) throws FileSystemException
|
||||||
{
|
{
|
||||||
@@ -309,7 +308,7 @@ public class FileSystem
|
|||||||
// Close all dangling open files
|
// Close all dangling open files
|
||||||
synchronized( m_openFiles )
|
synchronized( m_openFiles )
|
||||||
{
|
{
|
||||||
for(IMountedFile file : m_openFiles.keySet())
|
for(IMountedFile file : m_openFiles)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
file.close();
|
file.close();
|
||||||
@@ -667,7 +666,7 @@ public class FileSystem
|
|||||||
throw new FileSystemException("Too many files already open");
|
throw new FileSystemException("Too many files already open");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_openFiles.put( file, null );
|
m_openFiles.add( file );
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user