summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbytearray.cpp
diff options
context:
space:
mode:
authorhjk <qtc-committer@nokia.com>2009-06-18 15:01:09 (GMT)
committerhjk <qtc-committer@nokia.com>2009-06-19 06:39:38 (GMT)
commit9a5b40a011bd1b15a67d83564af55011761f8ad9 (patch)
treeba99ee4cccb04c1c19512995eb26edc7638aa6ba /src/corelib/tools/qbytearray.cpp
parentcce29e63108827f551c74221d0aafbbba891dd51 (diff)
downloadQt-9a5b40a011bd1b15a67d83564af55011761f8ad9.zip
Qt-9a5b40a011bd1b15a67d83564af55011761f8ad9.tar.gz
Qt-9a5b40a011bd1b15a67d83564af55011761f8ad9.tar.bz2
Small speedup of construction of uninitialized QByteArrays
Directly construct uninitialized QByteArrays of required size instead of default-constructing one and resizing it afterwards. Reviewed-by: mariusSO
Diffstat (limited to 'src/corelib/tools/qbytearray.cpp')
-rw-r--r--src/corelib/tools/qbytearray.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 142dfeb..2d4010d 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -2992,8 +2992,7 @@ QByteArray QByteArray::simplified() const
{
if (d->size == 0)
return *this;
- QByteArray result;
- result.resize(d->size);
+ QByteArray result(d->size, Qt::Uninitialized);
const char *from = d->data;
const char *fromend = from + d->size;
int outc=0;
@@ -3444,8 +3443,7 @@ QByteArray QByteArray::toBase64() const
const char padchar = '=';
int padlen = 0;
- QByteArray tmp;
- tmp.resize(((d->size * 4) / 3) + 3);
+ QByteArray tmp((d->size * 4) / 3 + 3, Qt::Uninitialized);
int i = 0;
char *out = tmp.data();
@@ -3783,8 +3781,7 @@ QByteArray QByteArray::fromBase64(const QByteArray &base64)
{
unsigned int buf = 0;
int nbits = 0;
- QByteArray tmp;
- tmp.resize((base64.size() * 3) / 4);
+ QByteArray tmp((base64.size() * 3) / 4, Qt::Uninitialized);
int offset = 0;
for (int i = 0; i < base64.size(); ++i) {
@@ -3832,8 +3829,7 @@ QByteArray QByteArray::fromBase64(const QByteArray &base64)
*/
QByteArray QByteArray::fromHex(const QByteArray &hexEncoded)
{
- QByteArray res;
- res.resize((hexEncoded.size() + 1)/ 2);
+ QByteArray res((hexEncoded.size() + 1)/ 2, Qt::Uninitialized);
uchar *result = (uchar *)res.data() + res.size();
bool odd_digit = true;
@@ -3870,8 +3866,7 @@ QByteArray QByteArray::fromHex(const QByteArray &hexEncoded)
*/
QByteArray QByteArray::toHex() const
{
- QByteArray hex;
- hex.resize(d->size*2);
+ QByteArray hex(d->size * 2, Qt::Uninitialized);
char *hexData = hex.data();
const uchar *data = (const uchar *)d->data;
for (int i = 0; i < d->size; ++i) {