Use the 'FindExInfoBasic' information level on supported OS (Windows 7 and later). Should further speed-up things.

This commit is contained in:
LoRd_MuldeR 2012-03-31 16:27:37 +02:00
parent 18b0993d3b
commit 17278fb7a6
5 changed files with 26 additions and 9 deletions

View File

@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 4
#define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 11
#define VER_LAMEXP_BUILD 942
#define VER_LAMEXP_BUILD 944
///////////////////////////////////////////////////////////////////////////////
// Tool versions (minimum expected versions!)

View File

@ -151,6 +151,7 @@ SIZE_T lamexp_dbg_private_bytes(void);
#define LAMEXP_DELETE_ARRAY(PTR) if(PTR) { delete [] PTR; PTR = NULL; }
#define LAMEXP_SAFE_FREE(PTR) if(PTR) { free((void*) PTR); PTR = NULL; }
#define LAMEXP_CLOSE(HANDLE) if(HANDLE != NULL && HANDLE != INVALID_HANDLE_VALUE) { CloseHandle(HANDLE); HANDLE = NULL; }
#define LAMEXP_MIN_OS_VER(VER_INFO, VER_MAJ, VER_MIN) ((HIWORD(VER_INFO) > (VER_MAJ)) || ((HIWORD(VER_INFO) == (VER_MAJ)) && (LOWORD(VER_INFO) >= (VER_MIN))))
#define QWCHAR(STR) reinterpret_cast<const wchar_t*>(STR.utf16())
#define WCHAR2QSTR(STR) QString::fromUtf16(reinterpret_cast<const unsigned short*>(STR))
#define LAMEXP_DYNCAST(OUT,CLASS,SRC) try { OUT = dynamic_cast<CLASS>(SRC); } catch(std::bad_cast) { OUT = NULL; }

View File

@ -212,6 +212,10 @@ QModelIndex QFileSystemModelEx::index(const QString &path, int column) const
QHash<const QString, bool> QFileSystemModelEx::s_hasSubfolderCache;
QMutex QFileSystemModelEx::s_hasSubfolderMutex;
void *QFileSystemModelEx::FindFirstFileExPtr = NULL;
bool QFileSystemModelEx::FindFirstFileExInitialized = false;
bool QFileSystemModelEx::FindFirstFileExInfoBasicOK = false;
bool QFileSystemModelEx::hasSubfoldersCached(const QString &path)
{
QMutexLocker lock(&s_hasSubfolderMutex);
@ -234,23 +238,22 @@ void QFileSystemModelEx::removeFromCache(const QString &path)
bool QFileSystemModelEx::hasSubfolders(const QString &path)
{
static bool FindFirstFileExInitialized = false;
static FindFirstFileExFun FindFirstFileExPtr = NULL;
if(!FindFirstFileExInitialized)
{
QLibrary Kernel32Lib("kernel32.dll");
FindFirstFileExPtr = (FindFirstFileExFun) Kernel32Lib.resolve("FindFirstFileExW");
FindFirstFileExPtr = Kernel32Lib.resolve("FindFirstFileExW");
DWORD osVersionNo = lamexp_get_os_version();
FindFirstFileExInfoBasicOK = LAMEXP_MIN_OS_VER(osVersionNo, 6, 1);
FindFirstFileExInitialized = true;
}
WIN32_FIND_DATAW findData;
bool bChildren = false;
HANDLE h = (FindFirstFileExPtr)
? FindFirstFileExPtr(QWCHAR(QDir::toNativeSeparators(path + "/*")), FindExInfoStandard, &findData, FindExSearchLimitToDirectories, NULL, 0)
? reinterpret_cast<FindFirstFileExFun>(FindFirstFileExPtr)(QWCHAR(QDir::toNativeSeparators(path + "/*")), (FindFirstFileExInfoBasicOK ? FindExInfoBasic : FindExInfoStandard), &findData, FindExSearchLimitToDirectories, NULL, 0)
: FindFirstFileW(QWCHAR(QDir::toNativeSeparators(path + "/*")), &findData);
if(h != INVALID_HANDLE_VALUE)
{
if(NO_DOT_OR_DOTDOT(findData.cFileName))
@ -266,5 +269,14 @@ bool QFileSystemModelEx::hasSubfolders(const QString &path)
}
FindClose(h);
}
else
{
DWORD err = GetLastError();
if((err == ERROR_NOT_SUPPORTED) || (err == ERROR_INVALID_PARAMETER))
{
qWarning("%s failed with error code #%u", FindFirstFileExPtr ? "FindFirstFileEx" : "FindFirstFile", err);
}
}
return bChildren;
}

View File

@ -43,6 +43,10 @@ private:
static QHash<const QString, bool> s_hasSubfolderCache;
static QMutex s_hasSubfolderMutex;
static void *FindFirstFileExPtr;
static bool FindFirstFileExInitialized;
static bool FindFirstFileExInfoBasicOK;
static bool hasSubfolders(const QString &path);
static bool hasSubfoldersCached(const QString &path);
static void removeFromCache(const QString &path);

View File

@ -69,7 +69,7 @@ AbstractTool::AbstractTool(void)
if(m_jobObjRefCount < 1U)
{
DWORD osVersionNo = lamexp_get_os_version();
if(((HIWORD(osVersionNo) == 5) && (LOWORD(osVersionNo) >= 1)) || (HIWORD(osVersionNo) > 5))
if(LAMEXP_MIN_OS_VER(osVersionNo, 5, 1))
{
if((!CreateJobObjectPtr) || (!SetInformationJobObjectPtr))
{