mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-12 11:10:29 +00:00
Merge pull request #156 from SquidDev-CC/feature/fs-find-performance
Performance improvements to fs.find
This commit is contained in:
commit
ec7a251c09
@ -466,9 +466,25 @@ public class FileSystem
|
||||
{
|
||||
// Match all the files on the system
|
||||
wildPath = sanitizePath( wildPath, true );
|
||||
|
||||
// If we don't have a wildcard at all just check the file exists
|
||||
int starIndex = wildPath.indexOf( '*' );
|
||||
if( starIndex == -1 )
|
||||
{
|
||||
return exists( wildPath ) ? new String[]{wildPath} : new String[0];
|
||||
}
|
||||
|
||||
// Find the all non-wildcarded directories. For instance foo/bar/baz* -> foo/bar
|
||||
int prevDir = wildPath.substring( 0, starIndex ).lastIndexOf( '/' );
|
||||
String startDir = prevDir == -1 ? "" : wildPath.substring( 0, prevDir );
|
||||
|
||||
// If this isn't a directory then just abort
|
||||
if( !isDir( startDir ) ) return new String[0];
|
||||
|
||||
// Scan as normal, starting from this directory
|
||||
Pattern wildPattern = Pattern.compile( "^\\Q" + wildPath.replaceAll( "\\*", "\\\\E[^\\\\/]*\\\\Q" ) + "\\E$" );
|
||||
List<String> matches = new ArrayList<String>();
|
||||
findIn( "", matches, wildPattern );
|
||||
findIn( startDir, matches, wildPattern );
|
||||
|
||||
// Return matches
|
||||
String[] array = new String[ matches.size() ];
|
||||
|
Loading…
Reference in New Issue
Block a user