optimize
This commit is contained in:
@@ -5,12 +5,16 @@
|
|||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
|
|
||||||
/* Search for "beginning*containing*ending". */
|
/* Search for "beginning*containing*ending". */
|
||||||
void FileSet::GetFilesMatching( const CString &sBeginning, const CString &sContaining, const CString &sEnding, vector<CString> &asOut, bool bOnlyDirs ) const
|
void FileSet::GetFilesMatching( const CString &sBeginning_, const CString &sContaining_, const CString &sEnding_, vector<CString> &asOut, bool bOnlyDirs ) const
|
||||||
{
|
{
|
||||||
/* "files" is a case-insensitive mapping, by filename. Use lower_bound to figure
|
/* "files" is a case-insensitive mapping, by filename. Use lower_bound to figure
|
||||||
* out where to start. */
|
* out where to start. */
|
||||||
CString sContainingLower = sContaining;
|
CString sBeginning = sBeginning_;
|
||||||
sContainingLower.ToLower();
|
sBeginning.ToLower();
|
||||||
|
CString sContaining = sContaining_;
|
||||||
|
sContaining.ToLower();
|
||||||
|
CString sEnding = sEnding_;
|
||||||
|
sEnding.ToLower();
|
||||||
|
|
||||||
set<File>::const_iterator i = files.lower_bound( File(sBeginning) );
|
set<File>::const_iterator i = files.lower_bound( File(sBeginning) );
|
||||||
for( ; i != files.end(); ++i )
|
for( ; i != files.end(); ++i )
|
||||||
@@ -20,31 +24,30 @@ void FileSet::GetFilesMatching( const CString &sBeginning, const CString &sConta
|
|||||||
if( bOnlyDirs && !f.dir )
|
if( bOnlyDirs && !f.dir )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
const CString &sPath = f.lname;
|
||||||
|
|
||||||
/* Check sBeginning. Once we hit a filename that no longer matches sBeginning,
|
/* Check sBeginning. Once we hit a filename that no longer matches sBeginning,
|
||||||
* we're past all possible matches in the sort, so stop. */
|
* we're past all possible matches in the sort, so stop. */
|
||||||
if( sBeginning.size() > f.name.size() )
|
if( sBeginning.size() > sPath.size() )
|
||||||
break; /* can't start with it */
|
break; /* can't start with it */
|
||||||
if( strnicmp(i->name, sBeginning, sBeginning.size()) )
|
if( sPath.compare(0, sBeginning.size(), sBeginning) )
|
||||||
break; /* doesn't start with it */
|
break; /* doesn't start with it */
|
||||||
|
|
||||||
/* Position the end starts on: */
|
/* Position the end starts on: */
|
||||||
int end_pos = int(f.name.size())-int(sEnding.size());
|
int end_pos = int(sPath.size())-int(sEnding.size());
|
||||||
|
|
||||||
/* Check end. */
|
/* Check end. */
|
||||||
if( end_pos < 0 )
|
if( end_pos < 0 )
|
||||||
continue; /* can't end with it */
|
continue; /* can't end with it */
|
||||||
if( stricmp(f.name.c_str()+end_pos, sEnding) )
|
if( sPath.compare(end_pos, string::npos, sEnding) )
|
||||||
continue; /* doesn't end with it */
|
continue; /* doesn't end with it */
|
||||||
|
|
||||||
/* Check sContaining. Do this last, since it's the slowest (substring
|
/* Check sContaining. Do this last, since it's the slowest (substring
|
||||||
* search instead of string match). */
|
* search instead of string match). */
|
||||||
if( sContaining.size() )
|
if( !sContaining.empty() )
|
||||||
{
|
{
|
||||||
CString name = f.name;
|
size_t pos = sPath.find( sContaining, sBeginning.size() );
|
||||||
name.ToLower();
|
if( pos == sPath.npos )
|
||||||
|
|
||||||
size_t pos = name.find( sContainingLower, sBeginning.size() );
|
|
||||||
if( pos == name.npos )
|
|
||||||
continue; /* doesn't contain it */
|
continue; /* doesn't contain it */
|
||||||
if( pos + sContaining.size() > unsigned(end_pos) )
|
if( pos + sContaining.size() > unsigned(end_pos) )
|
||||||
continue; /* found it but it overlaps with the end */
|
continue; /* found it but it overlaps with the end */
|
||||||
|
|||||||
Reference in New Issue
Block a user