summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qprocess_p.h
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2011-04-28 10:53:14 +0200
committerOlivier Goffart <olivier.goffart@nokia.com>2011-05-10 12:54:52 +0200
commit9ff8d1c34a74bd852a7eb2016b46ab2904340b05 (patch)
tree923330e5d529a8b616c4d4ecbf6c42d48f14a5b9 /src/corelib/io/qprocess_p.h
parent299d10549f5aff50cd6211eb3d3e58c17f13be81 (diff)
make QProcessEnvironment on Unix cache converted variable names
the converted keys also cache their hash, as they are used only for the purpose of looking up in a qhash. Reviewed-by: thiago Reviewed-by: dt (cherry picked from commit 18f1613aa8ece72d24ac10e28f06e3db1d8ce400)
Diffstat (limited to 'src/corelib/io/qprocess_p.h')
-rw-r--r--src/corelib/io/qprocess_p.h40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h
index 14fc9f32ce..9a9981efda 100644
--- a/src/corelib/io/qprocess_p.h
+++ b/src/corelib/io/qprocess_p.h
@@ -101,11 +101,33 @@ public:
inline Value prepareValue(const QString &value) const { return value; }
inline QString valueToString(const Value &value) const { return value; }
#else
- typedef QByteArray Key;
+ class Key
+ {
+ public:
+ Key() : hash(0) {}
+ explicit Key(const QByteArray &other) : key(other), hash(qHash(key)) {}
+ Key(const Key &other) { *this = other; }
+ bool operator==(const Key &other) const { return key == other.key; }
+
+ QByteArray key;
+ uint hash;
+ };
+
typedef QByteArray Value;
- inline Key prepareName(const QString &name) const { return name.toLocal8Bit(); }
- inline QString nameToString(const Key &name) const { return QString::fromLocal8Bit(name); }
+ inline Key prepareName(const QString &name) const
+ {
+ Key &ent = nameMap[name];
+ if (ent.key.isEmpty())
+ ent = Key(name.toLocal8Bit());
+ return ent;
+ }
+ inline QString nameToString(const Key &name) const
+ {
+ const QString sname = QString::fromLocal8Bit(name.key);
+ nameMap[sname] = name;
+ return sname;
+ }
inline Value prepareValue(const QString &value) const { return value.toLocal8Bit(); }
inline QString valueToString(const Value &value) const { return QString::fromLocal8Bit(value); }
#endif
@@ -113,14 +135,22 @@ public:
typedef QHash<Key, Value> Hash;
Hash hash;
+#ifdef Q_OS_UNIX
+ typedef QHash<QString, Key> NameHash;
+ mutable NameHash nameMap;
+#endif
+
static QProcessEnvironment fromList(const QStringList &list);
QStringList toList() const;
QStringList keys() const;
- void insert(const Hash &hash);
+ void insert(const QProcessEnvironmentPrivate &other);
};
-#ifdef Q_OS_WIN
Q_DECLARE_TYPEINFO(QProcessEnvironmentPrivate::Key, Q_MOVABLE_TYPE);
+
+#ifdef Q_OS_WIN
inline uint qHash(const QProcessEnvironmentPrivate::Key &key) { return qHash(key.toCaseFolded()); }
+#else
+inline uint qHash(const QProcessEnvironmentPrivate::Key &key) { return key.hash; }
#endif
class QProcessPrivate : public QIODevicePrivate