Rename QProcessEnvironmentPrivate::hash to vars

Also use auto for iterators to vars. This is a small refactoring in
preparation for changing type of vars to QMap.

Task-number: QTBUG-61315
Change-Id: I5731d7916b6f54a0da5be2da378c09a7688bd870
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thomas Sondergaard 2017-06-11 18:09:21 +02:00 committed by Thomas Sondergaard
parent 1a5fa66269
commit b438110028
5 changed files with 30 additions and 30 deletions

View File

@ -154,8 +154,8 @@ QT_BEGIN_NAMESPACE
QStringList QProcessEnvironmentPrivate::toList() const QStringList QProcessEnvironmentPrivate::toList() const
{ {
QStringList result; QStringList result;
result.reserve(hash.size()); result.reserve(vars.size());
for (Hash::const_iterator it = hash.cbegin(), end = hash.cend(); it != end; ++it) for (auto it = vars.cbegin(), end = vars.cend(); it != end; ++it)
result << nameToString(it.key()) + QLatin1Char('=') + valueToString(it.value()); result << nameToString(it.key()) + QLatin1Char('=') + valueToString(it.value());
return result; return result;
} }
@ -181,9 +181,9 @@ QProcessEnvironment QProcessEnvironmentPrivate::fromList(const QStringList &list
QStringList QProcessEnvironmentPrivate::keys() const QStringList QProcessEnvironmentPrivate::keys() const
{ {
QStringList result; QStringList result;
result.reserve(hash.size()); result.reserve(vars.size());
Hash::ConstIterator it = hash.constBegin(), auto it = vars.constBegin();
end = hash.constEnd(); const auto end = vars.constEnd();
for ( ; it != end; ++it) for ( ; it != end; ++it)
result << nameToString(it.key()); result << nameToString(it.key());
return result; return result;
@ -191,14 +191,14 @@ QStringList QProcessEnvironmentPrivate::keys() const
void QProcessEnvironmentPrivate::insert(const QProcessEnvironmentPrivate &other) void QProcessEnvironmentPrivate::insert(const QProcessEnvironmentPrivate &other)
{ {
Hash::ConstIterator it = other.hash.constBegin(), auto it = other.vars.constBegin();
end = other.hash.constEnd(); const auto end = other.vars.constEnd();
for ( ; it != end; ++it) for ( ; it != end; ++it)
hash.insert(it.key(), it.value()); vars.insert(it.key(), it.value());
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
QHash<QString, Key>::ConstIterator nit = other.nameMap.constBegin(), auto nit = other.nameMap.constBegin();
nend = other.nameMap.constEnd(); const auto nend = other.nameMap.constEnd();
for ( ; nit != nend; ++nit) for ( ; nit != nend; ++nit)
nameMap.insert(nit.key(), nit.value()); nameMap.insert(nit.key(), nit.value());
#endif #endif
@ -271,7 +271,7 @@ bool QProcessEnvironment::operator==(const QProcessEnvironment &other) const
if (d) { if (d) {
if (other.d) { if (other.d) {
QProcessEnvironmentPrivate::OrderedMutexLocker locker(d, other.d); QProcessEnvironmentPrivate::OrderedMutexLocker locker(d, other.d);
return d->hash == other.d->hash; return d->vars == other.d->vars;
} else { } else {
return isEmpty(); return isEmpty();
} }
@ -289,7 +289,7 @@ bool QProcessEnvironment::operator==(const QProcessEnvironment &other) const
bool QProcessEnvironment::isEmpty() const bool QProcessEnvironment::isEmpty() const
{ {
// Needs no locking, as no hash nodes are accessed // Needs no locking, as no hash nodes are accessed
return d ? d->hash.isEmpty() : true; return d ? d->vars.isEmpty() : true;
} }
/*! /*!
@ -301,7 +301,7 @@ bool QProcessEnvironment::isEmpty() const
void QProcessEnvironment::clear() void QProcessEnvironment::clear()
{ {
if (d) if (d)
d->hash.clear(); d->vars.clear();
// Unix: Don't clear d->nameMap, as the environment is likely to be // Unix: Don't clear d->nameMap, as the environment is likely to be
// re-populated with the same keys again. // re-populated with the same keys again.
} }
@ -318,7 +318,7 @@ bool QProcessEnvironment::contains(const QString &name) const
if (!d) if (!d)
return false; return false;
QProcessEnvironmentPrivate::MutexLocker locker(d); QProcessEnvironmentPrivate::MutexLocker locker(d);
return d->hash.contains(d->prepareName(name)); return d->vars.contains(d->prepareName(name));
} }
/*! /*!
@ -337,7 +337,7 @@ void QProcessEnvironment::insert(const QString &name, const QString &value)
{ {
// our re-impl of detach() detaches from null // our re-impl of detach() detaches from null
d.detach(); // detach before prepareName() d.detach(); // detach before prepareName()
d->hash.insert(d->prepareName(name), d->prepareValue(value)); d->vars.insert(d->prepareName(name), d->prepareValue(value));
} }
/*! /*!
@ -352,7 +352,7 @@ void QProcessEnvironment::remove(const QString &name)
{ {
if (d) { if (d) {
d.detach(); // detach before prepareName() d.detach(); // detach before prepareName()
d->hash.remove(d->prepareName(name)); d->vars.remove(d->prepareName(name));
} }
} }
@ -369,8 +369,8 @@ QString QProcessEnvironment::value(const QString &name, const QString &defaultVa
return defaultValue; return defaultValue;
QProcessEnvironmentPrivate::MutexLocker locker(d); QProcessEnvironmentPrivate::MutexLocker locker(d);
QProcessEnvironmentPrivate::Hash::ConstIterator it = d->hash.constFind(d->prepareName(name)); const auto it = d->vars.constFind(d->prepareName(name));
if (it == d->hash.constEnd()) if (it == d->vars.constEnd())
return defaultValue; return defaultValue;
return d->valueToString(it.value()); return d->valueToString(it.value());

View File

@ -48,7 +48,7 @@ QProcessEnvironment QProcessEnvironment::systemEnvironment()
__block QProcessEnvironment env; __block QProcessEnvironment env;
[[[NSProcessInfo processInfo] environment] [[[NSProcessInfo processInfo] environment]
enumerateKeysAndObjectsUsingBlock:^(NSString *name, NSString *value, BOOL *__unused stop) { enumerateKeysAndObjectsUsingBlock:^(NSString *name, NSString *value, BOOL *__unused stop) {
env.d->hash.insert( env.d->vars.insert(
QProcessEnvironmentPrivate::Key(QString::fromNSString(name).toLocal8Bit()), QProcessEnvironmentPrivate::Key(QString::fromNSString(name).toLocal8Bit()),
QProcessEnvironmentPrivate::Value(QString::fromNSString(value).toLocal8Bit())); QProcessEnvironmentPrivate::Value(QString::fromNSString(value).toLocal8Bit()));
}]; }];

View File

@ -197,17 +197,17 @@ public:
// do not need a lock, as they detach objects (however, we need to // do not need a lock, as they detach objects (however, we need to
// ensure that they really detach before using prepareName()). // ensure that they really detach before using prepareName()).
MutexLocker locker(&other); MutexLocker locker(&other);
hash = other.hash; vars = other.vars;
nameMap = other.nameMap; nameMap = other.nameMap;
// We need to detach our members, so that our mutex can protect them. // We need to detach our members, so that our mutex can protect them.
// As we are being detached, they likely would be detached a moment later anyway. // As we are being detached, they likely would be detached a moment later anyway.
hash.detach(); vars.detach();
nameMap.detach(); nameMap.detach();
} }
#endif #endif
typedef QHash<Key, Value> Hash; typedef QHash<Key, Value> Hash;
Hash hash; Hash vars;
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
typedef QHash<QString, Key> NameHash; typedef QHash<QString, Key> NameHash;

View File

@ -136,7 +136,7 @@ QProcessEnvironment QProcessEnvironment::systemEnvironment()
QByteArray name(entry, equal - entry); QByteArray name(entry, equal - entry);
QByteArray value(equal + 1); QByteArray value(equal + 1);
env.d->hash.insert(QProcessEnvironmentPrivate::Key(name), env.d->vars.insert(QProcessEnvironmentPrivate::Key(name),
QProcessEnvironmentPrivate::Value(value)); QProcessEnvironmentPrivate::Value(value));
} }
return env; return env;
@ -348,8 +348,8 @@ static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Hash &environm
envp[environment.count()] = 0; envp[environment.count()] = 0;
envp[environment.count() + 1] = 0; envp[environment.count() + 1] = 0;
QProcessEnvironmentPrivate::Hash::ConstIterator it = environment.constBegin(); auto it = environment.constBegin();
const QProcessEnvironmentPrivate::Hash::ConstIterator end = environment.constEnd(); const auto end = environment.constEnd();
for ( ; it != end; ++it) { for ( ; it != end; ++it) {
QByteArray key = it.key().key; QByteArray key = it.key().key;
QByteArray value = it.value().bytes(); QByteArray value = it.value().bytes();
@ -436,7 +436,7 @@ void QProcessPrivate::startProcess()
char **envp = 0; char **envp = 0;
if (environment.d.constData()) { if (environment.d.constData()) {
QProcessEnvironmentPrivate::MutexLocker locker(environment.d); QProcessEnvironmentPrivate::MutexLocker locker(environment.d);
envp = _q_dupEnvironment(environment.d.constData()->hash, &envc); envp = _q_dupEnvironment(environment.d.constData()->vars, &envc);
} }
// Encode the working directory if it's non-empty, otherwise just pass 0. // Encode the working directory if it's non-empty, otherwise just pass 0.

View File

@ -75,7 +75,7 @@ QProcessEnvironment QProcessEnvironment::systemEnvironment()
int nameLen = equal - entry; int nameLen = equal - entry;
QString name = QString::fromWCharArray(entry, nameLen); QString name = QString::fromWCharArray(entry, nameLen);
QString value = QString::fromWCharArray(equal + 1, entryLen - nameLen - 1); QString value = QString::fromWCharArray(equal + 1, entryLen - nameLen - 1);
env.d->hash.insert(QProcessEnvironmentPrivate::Key(name), value); env.d->vars.insert(QProcessEnvironmentPrivate::Key(name), value);
} }
entry += entryLen + 1; entry += entryLen + 1;
} }
@ -413,8 +413,8 @@ static QByteArray qt_create_environment(const QProcessEnvironmentPrivate::Hash &
} }
int pos = 0; int pos = 0;
QProcessEnvironmentPrivate::Hash::ConstIterator it = copy.constBegin(), auto it = copy.constBegin();
end = copy.constEnd(); const auto end = copy.constEnd();
static const wchar_t equal = L'='; static const wchar_t equal = L'=';
static const wchar_t nul = L'\0'; static const wchar_t nul = L'\0';
@ -475,7 +475,7 @@ void QProcessPrivate::startProcess()
QString args = qt_create_commandline(program, arguments); QString args = qt_create_commandline(program, arguments);
QByteArray envlist; QByteArray envlist;
if (environment.d.constData()) if (environment.d.constData())
envlist = qt_create_environment(environment.d.constData()->hash); envlist = qt_create_environment(environment.d.constData()->vars);
if (!nativeArguments.isEmpty()) { if (!nativeArguments.isEmpty()) {
if (!args.isEmpty()) if (!args.isEmpty())
args += QLatin1Char(' '); args += QLatin1Char(' ');