From 987458462994497f764baf253baca0faabdb63cc Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Sat, 6 Mar 2010 19:33:14 +0100 Subject: Avoid conversion to/from QChar in the cn codec to unicode Half of the instructions were jumps to the constructor or QChar. We can assume the char are on 16 bits and do the assignation directly. Reviewed-by: Andreas Kling --- src/plugins/codecs/cn/qgb18030codec.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/plugins/codecs/cn/qgb18030codec.cpp b/src/plugins/codecs/cn/qgb18030codec.cpp index e683fc0..3f2eec7 100644 --- a/src/plugins/codecs/cn/qgb18030codec.cpp +++ b/src/plugins/codecs/cn/qgb18030codec.cpp @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE #define Is3rdByte(c) (InRange((c), 0x81, 0xFE)) #define Is4thByte(c) (InRange((c), 0x30, 0x39)) -#define QValidChar(u) ((u) ? QChar((ushort)(u)) : QChar(QChar::ReplacementCharacter)) +#define qValidChar(u) ((u) ? (u) : static_cast(QChar::ReplacementCharacter)) /* User-defined areas: UDA 1: 0xAAA1 - 0xAFFE (564/0) UDA 2: 0xF8A1 - 0xFEFE (658/0) @@ -160,7 +160,7 @@ QString QGb18030Codec::convertToUnicode(const char* chars, int len, ConverterSta { uchar buf[4]; int nbuf = 0; - QChar replacement = QChar::ReplacementCharacter; + ushort replacement = QChar::ReplacementCharacter; if (state) { if (state->flags & ConvertInvalidToNull) replacement = QChar::Null; @@ -175,7 +175,7 @@ QString QGb18030Codec::convertToUnicode(const char* chars, int len, ConverterSta QString result; result.resize(len); int unicodeLen = 0; - QChar *const resultData = result.data(); + ushort *const resultData = reinterpret_cast(result.data()); //qDebug("QGb18030Decoder::toUnicode(const char* chars, int len = %d)", len); for (int i = 0; i < len; i++) { uchar ch = chars[i]; @@ -183,7 +183,7 @@ QString QGb18030Codec::convertToUnicode(const char* chars, int len, ConverterSta case 0: if (ch < 0x80) { // ASCII - resultData[unicodeLen] = QChar(ch); + resultData[unicodeLen] = ch; ++unicodeLen; } else if (Is1stByte(ch)) { // GB18030? @@ -203,7 +203,7 @@ QString QGb18030Codec::convertToUnicode(const char* chars, int len, ConverterSta int clen = 2; uint u = qt_Gb18030ToUnicode(buf, clen); if (clen == 2) { - resultData[unicodeLen] = QValidChar(u); + resultData[unicodeLen] = qValidChar(static_cast(u)); ++unicodeLen; } else { resultData[unicodeLen] = replacement; @@ -241,7 +241,7 @@ QString QGb18030Codec::convertToUnicode(const char* chars, int len, ConverterSta int clen = 4; uint u = qt_Gb18030ToUnicode(buf, clen); if (clen == 4) { - resultData[unicodeLen] = QValidChar(u); + resultData[unicodeLen] = qValidChar(u); ++unicodeLen; } else { resultData[unicodeLen] = replacement; @@ -356,7 +356,7 @@ QString QGbkCodec::convertToUnicode(const char* chars, int len, ConverterState * int clen = 2; uint u = qt_Gb18030ToUnicode(buf, clen); if (clen == 2) { - result += QValidChar(u); + result += qValidChar(u); } else { result += replacement; ++invalid; @@ -459,7 +459,7 @@ QString QGb2312Codec::convertToUnicode(const char* chars, int len, ConverterStat { uchar buf[2]; int nbuf = 0; - QChar replacement = QChar::ReplacementCharacter; + ushort replacement = QChar::ReplacementCharacter; if (state) { if (state->flags & ConvertInvalidToNull) replacement = QChar::Null; @@ -472,7 +472,7 @@ QString QGb2312Codec::convertToUnicode(const char* chars, int len, ConverterStat QString result; result.resize(len); int unicodeLen = 0; - QChar *const resultData = result.data(); + ushort *const resultData = reinterpret_cast(result.data()); //qDebug("QGb2312Decoder::toUnicode(const char* chars, int len = %d)", len); for (int i=0; i(u)); ++unicodeLen; } else { resultData[unicodeLen] = replacement; -- cgit v0.12