summaryrefslogtreecommitdiffstats
path: root/src/corelib/codecs/qiconvcodec.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/codecs/qiconvcodec.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/codecs/qiconvcodec.cpp')
-rw-r--r--src/corelib/codecs/qiconvcodec.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/corelib/codecs/qiconvcodec.cpp b/src/corelib/codecs/qiconvcodec.cpp
index 6b9c77b..1bf76ea 100644
--- a/src/corelib/codecs/qiconvcodec.cpp
+++ b/src/corelib/codecs/qiconvcodec.cpp
@@ -225,11 +225,10 @@ QString QIconvCodec::convertToUnicode(const char* chars, int len, ConverterState
char *inBytes = const_cast<char *>(chars);
#endif
- QByteArray in;
if (remainingCount) {
// we have to prepend the remaining bytes from the previous conversion
inBytesLeft += remainingCount;
- in.resize(inBytesLeft);
+ QByteArray in(inBytesLeft, Qt::Uninitialized);
inBytes = in.data();
memcpy(in.data(), remainingBuffer, remainingCount);
@@ -238,9 +237,8 @@ QString QIconvCodec::convertToUnicode(const char* chars, int len, ConverterState
remainingCount = 0;
}
- QByteArray ba;
size_t outBytesLeft = len * 2 + 2;
- ba.resize(outBytesLeft);
+ QByteArray ba(outBytesLeft, Qt::Uninitialized);
char *outBytes = ba.data();
do {
size_t ret = iconv(state->cd, &inBytes, &inBytesLeft, &outBytes, &outBytesLeft);
@@ -328,8 +326,7 @@ QByteArray QIconvCodec::convertFromUnicode(const QChar *uc, int len, ConverterSt
state = new IconvState(QIconvCodec::createIconv_t(0, UTF16));
if (state->cd != reinterpret_cast<iconv_t>(-1)) {
size_t outBytesLeft = len + 3; // +3 for the BOM
- QByteArray ba;
- ba.resize(outBytesLeft);
+ QByteArray ba(outBytesLeft, Qt::Uninitialized);
outBytes = ba.data();
#if !defined(NO_BOM)
@@ -358,18 +355,16 @@ QByteArray QIconvCodec::convertFromUnicode(const QChar *uc, int len, ConverterSt
}
size_t outBytesLeft = len;
- QByteArray ba;
- ba.resize(outBytesLeft);
+ QByteArray ba(outBytesLeft, Qt::Uninitialized);
outBytes = ba.data();
// now feed iconv() the real data
inBytes = const_cast<char *>(reinterpret_cast<const char *>(uc));
inBytesLeft = len * sizeof(QChar);
- QByteArray in;
if (convState && convState->remainingChars) {
// we have one surrogate char to be prepended
- in.resize(sizeof(QChar) + len);
+ QByteArray in(sizeof(QChar) + len, Qt::Uninitialized);
inBytes = in.data();
QChar remaining = convState->state_data[0];