From 48d4baca5becf0966ad02f3f316cd9894ef6d5c3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 13 May 2009 16:54:14 +0200 Subject: Execute some small performance improvements in QProcessEnvironment If d == 0, then we know we have no items. Therefore, removing or clearing is an idempotent action. So instead of detaching, leave d == 0. In the search function, avoid converting the defaultValue to the internal representation. --- src/corelib/io/qprocess.cpp | 13 +++++++++---- src/corelib/io/qprocess_p.h | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 7c13bf0..733887a 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -293,7 +293,8 @@ bool QProcessEnvironment::isEmpty() const */ void QProcessEnvironment::clear() { - d->hash.clear(); + if (d) + d->hash.clear(); } /*! @@ -345,7 +346,8 @@ void QProcessEnvironment::insert(const QString &name, const QString &value) */ void QProcessEnvironment::remove(const QString &name) { - d->hash.remove(prepareName(name)); + if (d) + d->hash.remove(prepareName(name)); } /*! @@ -364,8 +366,11 @@ QString QProcessEnvironment::value(const QString &name, const QString &defaultVa if (!d) return defaultValue; - QProcessEnvironmentPrivate::Unit result = d->hash.value(prepareName(name), prepareValue(defaultValue)); - return valueToString(result); + QProcessEnvironmentPrivate::Hash::ConstIterator it = d->hash.constFind(prepareName(name)); + if (it == d->hash.constEnd()) + return defaultValue; + + return valueToString(it.value()); } /*! diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h index 1e2979b..b581e91 100644 --- a/src/corelib/io/qprocess_p.h +++ b/src/corelib/io/qprocess_p.h @@ -86,7 +86,8 @@ public: #else typedef QByteArray Unit; #endif - QHash hash; + typedef QHash Hash; + Hash hash; static QProcessEnvironment fromList(const QStringList &list); QStringList toList() const; -- cgit v0.12