summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstring.cpp
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-04-07 12:12:52 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-04-29 16:32:38 (GMT)
commitdd4bb9811a5fa55bd0dff805e55d72d14bcafd48 (patch)
treea98a777987773fcc7bbe4382421b1f380fab8855 /src/corelib/tools/qstring.cpp
parent801065f55c1232fddccfcf4a434b709080a3baed (diff)
downloadQt-dd4bb9811a5fa55bd0dff805e55d72d14bcafd48.zip
Qt-dd4bb9811a5fa55bd0dff805e55d72d14bcafd48.tar.gz
Qt-dd4bb9811a5fa55bd0dff805e55d72d14bcafd48.tar.bz2
add QString::setRawData() and revive QByteArray::setRawData()
this is solely for optimization purposes - saves a free()/malloc() pair each time an existing object is re-used.
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r--src/corelib/tools/qstring.cpp40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 2f12b80..0169b20 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -7056,7 +7056,7 @@ void QString::updateProperties() const
'\\0'-terminated string (although utf16() does, at the cost of
copying the raw data).
- \sa fromUtf16()
+ \sa fromUtf16(), setRawData()
*/
QString QString::fromRawData(const QChar *unicode, int size)
{
@@ -7075,6 +7075,44 @@ QString QString::fromRawData(const QChar *unicode, int size)
return QString(x, 0);
}
+/*!
+ \since 4.7
+
+ Resets the QString to use the first \a size Unicode characters
+ in the array \a unicode. The data in \a unicode is \e not
+ copied. The caller must be able to guarantee that \a unicode will
+ not be deleted or modified as long as the QString (or an
+ unmodified copy of it) exists.
+
+ This function can be used instead of fromRawData() to re-use
+ existings QString objects to save memory re-allocations.
+
+ \sa fromRawData()
+*/
+QString &QString::setRawData(const QChar *unicode, int size)
+{
+ if (d->ref != 1 || d->alloc) {
+ *this = fromRawData(unicode, size);
+ } else {
+#ifdef QT3_SUPPORT
+ if (d->asciiCache) {
+ Q_ASSERT(asciiCache);
+ asciiCache->remove(d);
+ }
+#endif
+ if (unicode) {
+ d->data = (ushort *)unicode;
+ } else {
+ d->data = d->array;
+ size = 0;
+ }
+ d->alloc = d->size = size;
+ *d->array = '\0';
+ d->clean = d->asciiCache = d->simpletext = d->righttoleft = d->capacity = 0;
+ }
+ return *this;
+}
+
/*! \class QLatin1String
\brief The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.