diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2018-05-29 11:42:40 -0500 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2018-07-04 03:04:43 +0000 |
commit | e79b56e50474f67044565361ef622a10eaad76ed (patch) | |
tree | bb7e4564b13993a7c0af3de36d911e93e226db0d /src/corelib/codecs | |
parent | d0427759c67704fe0f1b04edadd4d30329af268c (diff) |
This is just the low-hanging fruit. Those algorithms could be much
further improved, but they are so seldom-used that it's not worth it.
Change-Id: I6a540578e810472bb455fffd15332b2a7a1ac901
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/corelib/codecs')
-rw-r--r-- | src/corelib/codecs/qutfcodec.cpp | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp index 96be45ff4e..26c68cdee5 100644 --- a/src/corelib/codecs/qutfcodec.cpp +++ b/src/corelib/codecs/qutfcodec.cpp @@ -756,26 +756,16 @@ QByteArray QUtf16::convertFromUnicode(const QChar *uc, int len, QTextCodec::Conv char *data = d.data(); if (!state || !(state->flags & QTextCodec::IgnoreHeader)) { QChar bom(QChar::ByteOrderMark); - if (endian == BigEndianness) { - data[0] = bom.row(); - data[1] = bom.cell(); - } else { - data[0] = bom.cell(); - data[1] = bom.row(); - } + if (endian == BigEndianness) + qToBigEndian(bom.unicode(), data); + else + qToLittleEndian(bom.unicode(), data); data += 2; } - if (endian == BigEndianness) { - for (int i = 0; i < len; ++i) { - *(data++) = uc[i].row(); - *(data++) = uc[i].cell(); - } - } else { - for (int i = 0; i < len; ++i) { - *(data++) = uc[i].cell(); - *(data++) = uc[i].row(); - } - } + if (endian == BigEndianness) + qToBigEndian<ushort>(uc, len, data); + else + qToLittleEndian<ushort>(uc, len, data); if (state) { state->remainingChars = 0; @@ -891,20 +881,14 @@ QByteArray QUtf32::convertFromUnicode(const QChar *uc, int len, QTextCodec::Conv if (endian == BigEndianness) { while (i.hasNext()) { uint cp = i.next(); - - *(data++) = cp >> 24; - *(data++) = (cp >> 16) & 0xff; - *(data++) = (cp >> 8) & 0xff; - *(data++) = cp & 0xff; + qToBigEndian(cp, data); + data += 4; } } else { while (i.hasNext()) { uint cp = i.next(); - - *(data++) = cp & 0xff; - *(data++) = (cp >> 8) & 0xff; - *(data++) = (cp >> 16) & 0xff; - *(data++) = cp >> 24; + qToLittleEndian(cp, data); + data += 4; } } |