Performance optimisation for MSW direcotry timestamping.

This commit is contained in:
Jeff Young 2018-08-07 20:16:25 +01:00
parent 84504599ce
commit d63d0c40ef
1 changed files with 22 additions and 16 deletions

View File

@ -707,28 +707,34 @@ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec )
{ {
long long timestamp = 0; long long timestamp = 0;
#ifdef __WINDOWS__ #if defined(__WIN32__)
// wxFileName construction is egregiously slow. Construct it once and just swap out // Win32 version.
// the filename thereafter. // Save time by not searching for each path twice: once in wxDir.GetNext() and once in
WX_FILENAME fn( aDirPath, wxT( "dummyName" ) ); // wxFileName.GetModificationTime(). Also cuts out wxWidgets string-matching and case
wxDir dir( aDirPath ); // conversion by staying on the MSW side of things.
wxString fullname; std::string filespec( aDirPath.t_str() );
filespec += '\\';
filespec += aFilespec.t_str();
if( dir.IsOpened() ) WIN32_FIND_DATA findData;
wxDateTime lastModDate;
HANDLE fileHandle = ::FindFirstFile( filespec, &findData );
if( fileHandle != INVALID_HANDLE_VALUE )
{ {
if( dir.GetFirst( &fullname, aFilespec ) ) do
{ {
do ConvertFileTimeToWx( lastModDate, findData.ftLastWriteTime );
{ timestamp += lastModDate.GetValue().GetValue();
fn.SetFullName( fullname );
timestamp += fn.GetTimestamp();
}
while( dir.GetNext( &fullname ) );
} }
while ( FindNextFile( fileHandle, &findData ) != 0);
} }
FindClose( fileHandle );
#else #else
// POSIX version. Save time by not converting between encodings -- do everything on // POSIX version.
// the file-system side. // Save time by not converting between encodings -- do everything on the file-system side.
std::string filespec( aFilespec.fn_str() ); std::string filespec( aFilespec.fn_str() );
std::string dir_path( aDirPath.fn_str() ); std::string dir_path( aDirPath.fn_str() );