summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2011-04-21 21:34:59 +0200
committerOlivier Goffart <olivier.goffart@nokia.com>2011-05-10 12:54:52 +0200
commit61b85df09b80374f2d4e5d2f6004d020b3cb05a8 (patch)
treea0b10beca1ed4e94757dcce8e11f3022e946f113
parent5a4df43c71e7a7f45248a7f8cadd7f8b7c09500c (diff)
make QProcessEnvironment on Unix cache converted values
values are converted between byte arrays and qstrings on demand. this makes it feasible to use the class as a generic environment container with fast reading and writing access. Reviewed-by: thiago Reviewed-by: dt (cherry picked from commit 7aa4ecdedba60ac4cbc07a774ae9d834677002e9)
-rw-r--r--src/corelib/io/qprocess_p.h37
-rw-r--r--src/corelib/io/qprocess_unix.cpp2
2 files changed, 35 insertions, 4 deletions
diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h
index 9a9981efda..251f8bc772 100644
--- a/src/corelib/io/qprocess_p.h
+++ b/src/corelib/io/qprocess_p.h
@@ -113,7 +113,35 @@ public:
uint hash;
};
- typedef QByteArray Value;
+ class Value
+ {
+ public:
+ Value() {}
+ Value(const Value &other) { *this = other; }
+ explicit Value(const QString &value) : stringValue(value) {}
+ explicit Value(const QByteArray &value) : byteValue(value) {}
+ bool operator==(const Value &other) const
+ {
+ return byteValue.isEmpty() && other.byteValue.isEmpty()
+ ? stringValue == other.stringValue
+ : bytes() == other.bytes();
+ }
+ QByteArray bytes() const
+ {
+ if (byteValue.isEmpty() && !stringValue.isEmpty())
+ byteValue = stringValue.toLocal8Bit();
+ return byteValue;
+ }
+ QString string() const
+ {
+ if (stringValue.isEmpty() && !byteValue.isEmpty())
+ stringValue = QString::fromLocal8Bit(byteValue);
+ return stringValue;
+ }
+
+ mutable QByteArray byteValue;
+ mutable QString stringValue;
+ };
inline Key prepareName(const QString &name) const
{
@@ -128,8 +156,8 @@ public:
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); }
+ inline Value prepareValue(const QString &value) const { return Value(value); }
+ inline QString valueToString(const Value &value) const { return value.string(); }
#endif
typedef QHash<Key, Value> Hash;
@@ -146,6 +174,9 @@ public:
void insert(const QProcessEnvironmentPrivate &other);
};
Q_DECLARE_TYPEINFO(QProcessEnvironmentPrivate::Key, Q_MOVABLE_TYPE);
+#ifdef Q_OS_UNIX
+Q_DECLARE_TYPEINFO(QProcessEnvironmentPrivate::Value, Q_MOVABLE_TYPE);
+#endif
#ifdef Q_OS_WIN
inline uint qHash(const QProcessEnvironmentPrivate::Key &key) { return qHash(key.toCaseFolded()); }
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index 4e50bc546b..7a9e75d534 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -510,7 +510,7 @@ static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Hash &environm
const QProcessEnvironmentPrivate::Hash::ConstIterator end = environment.constEnd();
for ( ; it != end; ++it) {
QByteArray key = it.key().key;
- QByteArray value = it.value();
+ QByteArray value = it.value().bytes();
key.reserve(key.length() + 1 + value.length());
key.append('=');
key.append(value);