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 result;
result.reserve(hash.size());
for (Hash::const_iterator it = hash.cbegin(), end = hash.cend(); it != end; ++it)
result.reserve(vars.size());
for (auto it = vars.cbegin(), end = vars.cend(); it != end; ++it)
result << nameToString(it.key()) + QLatin1Char('=') + valueToString(it.value());
return result;
}
@ -181,9 +181,9 @@ QProcessEnvironment QProcessEnvironmentPrivate::fromList(const QStringList &list
QStringList QProcessEnvironmentPrivate::keys() const
{
QStringList result;
result.reserve(hash.size());
Hash::ConstIterator it = hash.constBegin(),
end = hash.constEnd();
result.reserve(vars.size());
auto it = vars.constBegin();
const auto end = vars.constEnd();
for ( ; it != end; ++it)
result << nameToString(it.key());
return result;
@ -191,14 +191,14 @@ QStringList QProcessEnvironmentPrivate::keys() const
void QProcessEnvironmentPrivate::insert(const QProcessEnvironmentPrivate &other)
{
Hash::ConstIterator it = other.hash.constBegin(),
end = other.hash.constEnd();
auto it = other.vars.constBegin();
const auto end = other.vars.constEnd();
for ( ; it != end; ++it)
hash.insert(it.key(), it.value());
vars.insert(it.key(), it.value());
#ifdef Q_OS_UNIX
QHash<QString, Key>::ConstIterator nit = other.nameMap.constBegin(),
nend = other.nameMap.constEnd();
auto nit = other.nameMap.constBegin();
const auto nend = other.nameMap.constEnd();
for ( ; nit != nend; ++nit)
nameMap.insert(nit.key(), nit.value());
#endif
@ -271,7 +271,7 @@ bool QProcessEnvironment::operator==(const QProcessEnvironment &other) const
if (d) {
if (other.d) {
QProcessEnvironmentPrivate::OrderedMutexLocker locker(d, other.d);
return d->hash == other.d->hash;
return d->vars == other.d->vars;
} else {
return isEmpty();
}
@ -289,7 +289,7 @@ bool QProcessEnvironment::operator==(const QProcessEnvironment &other) const
bool QProcessEnvironment::isEmpty() const
{
// 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()
{
if (d)
d->hash.clear();
d->vars.clear();
// Unix: Don't clear d->nameMap, as the environment is likely to be
// re-populated with the same keys again.
}
@ -318,7 +318,7 @@ bool QProcessEnvironment::contains(const QString &name) const
if (!d)
return false;
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
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) {
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;
QProcessEnvironmentPrivate::MutexLocker locker(d);
QProcessEnvironmentPrivate::Hash::ConstIterator it = d->hash.constFind(d->prepareName(name));
if (it == d->hash.constEnd())
const auto it = d->vars.constFind(d->prepareName(name));
if (it == d->vars.constEnd())
return defaultValue;
return d->valueToString(it.value());

View File

@ -48,7 +48,7 @@ QProcessEnvironment QProcessEnvironment::systemEnvironment()
__block QProcessEnvironment env;
[[[NSProcessInfo processInfo] environment]
enumerateKeysAndObjectsUsingBlock:^(NSString *name, NSString *value, BOOL *__unused stop) {
env.d->hash.insert(
env.d->vars.insert(
QProcessEnvironmentPrivate::Key(QString::fromNSString(name).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
// ensure that they really detach before using prepareName()).
MutexLocker locker(&other);
hash = other.hash;
vars = other.vars;
nameMap = other.nameMap;
// 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.
hash.detach();
vars.detach();
nameMap.detach();
}
#endif
typedef QHash<Key, Value> Hash;
Hash hash;
Hash vars;
#ifdef Q_OS_UNIX
typedef QHash<QString, Key> NameHash;

View File

@ -136,7 +136,7 @@ QProcessEnvironment QProcessEnvironment::systemEnvironment()
QByteArray name(entry, equal - entry);
QByteArray value(equal + 1);
env.d->hash.insert(QProcessEnvironmentPrivate::Key(name),
env.d->vars.insert(QProcessEnvironmentPrivate::Key(name),
QProcessEnvironmentPrivate::Value(value));
}
return env;
@ -348,8 +348,8 @@ static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Hash &environm
envp[environment.count()] = 0;
envp[environment.count() + 1] = 0;
QProcessEnvironmentPrivate::Hash::ConstIterator it = environment.constBegin();
const QProcessEnvironmentPrivate::Hash::ConstIterator end = environment.constEnd();
auto it = environment.constBegin();
const auto end = environment.constEnd();
for ( ; it != end; ++it) {
QByteArray key = it.key().key;
QByteArray value = it.value().bytes();
@ -436,7 +436,7 @@ void QProcessPrivate::startProcess()
char **envp = 0;
if (environment.d.constData()) {
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.

View File

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