summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbytearray.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/qbytearray.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/qbytearray.cpp')
-rw-r--r--src/corelib/tools/qbytearray.cpp39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index c5f70b0..29a7263 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -3814,7 +3814,7 @@ QByteArray QByteArray::number(double n, char f, int prec)
accepting a \c{const char *} expected to be '\\0'-terminated will
fail.
- \sa data(), constData()
+ \sa setRawData(), data(), constData()
*/
QByteArray QByteArray::fromRawData(const char *data, int size)
@@ -3834,6 +3834,37 @@ QByteArray QByteArray::fromRawData(const char *data, int size)
}
/*!
+ \since 4.7
+
+ Resets the QByteArray to use the first \a size bytes of the
+ \a data array. The bytes are \e not copied. The QByteArray will
+ contain the \a data pointer. The caller guarantees that \a data
+ will not be deleted or modified as long as this QByteArray and any
+ copies of it exist that have not been modified.
+
+ This function can be used instead of fromRawData() to re-use
+ existings QByteArray objects to save memory re-allocations.
+
+ \sa fromRawData(), data(), constData()
+*/
+QByteArray &QByteArray::setRawData(const char *data, uint size)
+{
+ if (d->ref != 1 || d->alloc) {
+ *this = fromRawData(data, size);
+ } else {
+ if (data) {
+ d->data = const_cast<char *>(data);
+ } else {
+ d->data = d->array;
+ size = 0;
+ }
+ d->alloc = d->size = size;
+ *d->array = '\0';
+ }
+ return *this;
+}
+
+/*!
Returns a decoded copy of the Base64 array \a base64. Input is not checked
for validity; invalid characters in the input are skipped, enabling the
decoding process to continue with subsequent characters.
@@ -4228,12 +4259,6 @@ QByteArray QByteArray::toPercentEncoding(const QByteArray &exclude, const QByteA
*/
/*!
- \fn QByteArray& QByteArray::setRawData(const char *a, uint n)
-
- Use fromRawData() instead.
-*/
-
-/*!
\fn void QByteArray::resetRawData(const char *data, uint n)
Use clear() instead.