diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-04-21 19:34:59 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-04-29 10:59:53 (GMT) |
commit | 7aa4ecdedba60ac4cbc07a774ae9d834677002e9 (patch) | |
tree | 7e5907eb36517234769375e3e6666203e95ef2a4 /src/corelib/io/qprocess_p.h | |
parent | 60194ad0ea68d7c82b4729119d122dcfeb909842 (diff) | |
download | Qt-7aa4ecdedba60ac4cbc07a774ae9d834677002e9.zip Qt-7aa4ecdedba60ac4cbc07a774ae9d834677002e9.tar.gz Qt-7aa4ecdedba60ac4cbc07a774ae9d834677002e9.tar.bz2 |
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
Diffstat (limited to 'src/corelib/io/qprocess_p.h')
-rw-r--r-- | src/corelib/io/qprocess_p.h | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h index 9a9981e..251f8bc 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()); } |