summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Schuberth <sschuberth@gmail.com>2009-12-16 15:33:21 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-06 13:50:19 +0200
commit09a11069e7b0aafcfccad78d7f69eeb1fadd5494 (patch)
tree2e38a20f829d86a3a4055abe3771bd3beb6f74d3
parentdc6852ca63ab56eddb8a8843b0c383d51a4020a9 (diff)
Improve the QWinSettingsPrivate constructor's performance
This is mainly achieved by modifying the program flow to require fewer string comparisons and conversions. Change-Id: I9887623b9c05fe76460fc725d6534d16bd9f9e59 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
-rw-r--r--src/corelib/io/qsettings_win.cpp47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp
index 1d410862f0..2d086efd4e 100644
--- a/src/corelib/io/qsettings_win.cpp
+++ b/src/corelib/io/qsettings_win.cpp
@@ -433,27 +433,32 @@ QWinSettingsPrivate::QWinSettingsPrivate(QString rPath)
{
deleteWriteHandleOnExit = false;
- if (rPath.startsWith(QLatin1String("\\")))
- rPath = rPath.mid(1);
-
- if (rPath.startsWith(QLatin1String("HKEY_CURRENT_USER\\")))
- regList.append(RegistryKey(HKEY_CURRENT_USER, rPath.mid(18), false));
- else if (rPath == QLatin1String("HKEY_CURRENT_USER"))
- regList.append(RegistryKey(HKEY_CURRENT_USER, QString(), false));
- else if (rPath.startsWith(QLatin1String("HKEY_LOCAL_MACHINE\\")))
- regList.append(RegistryKey(HKEY_LOCAL_MACHINE, rPath.mid(19), false));
- else if (rPath == QLatin1String("HKEY_LOCAL_MACHINE"))
- regList.append(RegistryKey(HKEY_LOCAL_MACHINE, QString(), false));
- else if (rPath.startsWith(QLatin1String("HKEY_CLASSES_ROOT\\")))
- regList.append(RegistryKey(HKEY_CLASSES_ROOT, rPath.mid(18), false));
- else if (rPath == QLatin1String("HKEY_CLASSES_ROOT"))
- regList.append(RegistryKey(HKEY_CLASSES_ROOT, QString(), false));
- else if (rPath.startsWith(QLatin1String("HKEY_USERS\\")))
- regList.append(RegistryKey(HKEY_USERS, rPath.mid(11), false));
- else if (rPath == QLatin1String("HKEY_USERS"))
- regList.append(RegistryKey(HKEY_USERS, QString(), false));
- else
- regList.append(RegistryKey(HKEY_LOCAL_MACHINE, rPath, false));
+ if (rPath.startsWith(QLatin1Char('\\')))
+ rPath.remove(0, 1);
+
+ int keyLength;
+ HKEY keyName;
+
+ if (rPath.startsWith(QLatin1String("HKEY_CURRENT_USER"))) {
+ keyLength = 17;
+ keyName = HKEY_CURRENT_USER;
+ } else if (rPath.startsWith(QLatin1String("HKEY_LOCAL_MACHINE"))) {
+ keyLength = 18;
+ keyName = HKEY_LOCAL_MACHINE;
+ } else if (rPath.startsWith(QLatin1String("HKEY_CLASSES_ROOT"))) {
+ keyLength = 17;
+ keyName = HKEY_CLASSES_ROOT;
+ } else if (rPath.startsWith(QLatin1String("HKEY_USERS"))) {
+ keyLength = 10;
+ keyName = HKEY_USERS;
+ } else {
+ return;
+ }
+
+ if (rPath.length() == keyLength)
+ regList.append(RegistryKey(keyName, QString(), false));
+ else if (rPath[keyLength] == QLatin1Char('\\'))
+ regList.append(RegistryKey(keyName, rPath.mid(keyLength+1), false));
}
bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVariant *value) const