Avoid converting data unnecessarily

This commit is contained in:
James Clark 1998-06-01 05:55:23 +00:00
parent 698686457e
commit 496af54711
3 changed files with 55 additions and 21 deletions

View file

@ -29,6 +29,7 @@ Contributor(s):
#define XmlConvert XmlUtf16Convert
#define XmlGetInternalEncoding XmlGetUtf16InternalEncoding
#define XmlEncode XmlUtf16Encode
#define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((unsigned long)s) & 1))
#define xmlstrchr wcschr
#define xmlstrcmp wcscmp
#define XML_T(x) L ## x
@ -38,6 +39,7 @@ typedef unsigned short ICHAR;
#define XmlConvert XmlUtf8Convert
#define XmlGetInternalEncoding XmlGetUtf8InternalEncoding
#define XmlEncode XmlUtf8Encode
#define MUST_CONVERT(enc, s) (!(enc)->isUtf8)
#define xmlstrchr strchr
#define xmlstrcmp strcmp
#define XML_T(x) x
@ -1046,9 +1048,15 @@ doContent(XML_Parser parser,
return XML_ERROR_NONE;
}
if (characterDataHandler) {
ICHAR *dataPtr = (ICHAR *)dataBuf;
XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
characterDataHandler(userData, dataBuf, dataPtr - (ICHAR *)dataBuf);
if (MUST_CONVERT(enc, s)) {
ICHAR *dataPtr = (ICHAR *)dataBuf;
XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
characterDataHandler(userData, dataBuf, dataPtr - (ICHAR *)dataBuf);
}
else
characterDataHandler(userData,
(XML_Char *)s,
(XML_Char *)end - (XML_Char *)s);
}
if (startTagLevel == 0) {
errorPtr = end;
@ -1061,11 +1069,17 @@ doContent(XML_Parser parser,
return XML_ERROR_NONE;
case XML_TOK_DATA_CHARS:
if (characterDataHandler) {
do {
ICHAR *dataPtr = (ICHAR *)dataBuf;
XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
characterDataHandler(userData, dataBuf, dataPtr - (ICHAR *)dataBuf);
} while (s != next);
if (MUST_CONVERT(enc, s)) {
do {
ICHAR *dataPtr = (ICHAR *)dataBuf;
XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
characterDataHandler(userData, dataBuf, dataPtr - (ICHAR *)dataBuf);
} while (s != next);
}
else
characterDataHandler(userData,
(XML_Char *)s,
(XML_Char *)next - (XML_Char *)s);
}
break;
case XML_TOK_PI:
@ -1214,11 +1228,17 @@ enum XML_Error doCdataSection(XML_Parser parser,
break;
case XML_TOK_DATA_CHARS:
if (characterDataHandler) {
do {
ICHAR *dataPtr = (ICHAR *)dataBuf;
XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
characterDataHandler(userData, dataBuf, dataPtr - (ICHAR *)dataBuf);
} while (s != next);
if (MUST_CONVERT(enc, s)) {
do {
ICHAR *dataPtr = (ICHAR *)dataBuf;
XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
characterDataHandler(userData, dataBuf, dataPtr - (ICHAR *)dataBuf);
} while (s != next);
}
else
characterDataHandler(userData,
(XML_Char *)s,
(XML_Char *)next - (XML_Char *)s);
}
break;
case XML_TOK_INVALID:

View file

@ -178,7 +178,7 @@ void utf8_toUtf16(const ENCODING *enc,
}
static const struct normal_encoding utf8_encoding = {
{ VTABLE1, utf8_toUtf8, utf8_toUtf16, 1 },
{ VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
{
#include "asciitab.h"
#include "utf8tab.h"
@ -186,7 +186,7 @@ static const struct normal_encoding utf8_encoding = {
};
static const struct normal_encoding internal_utf8_encoding = {
{ VTABLE1, utf8_toUtf8, utf8_toUtf16, 1 },
{ VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
{
#include "iasciitab.h"
#include "utf8tab.h"
@ -228,7 +228,7 @@ void latin1_toUtf16(const ENCODING *enc,
}
static const struct normal_encoding latin1_encoding = {
{ VTABLE1, latin1_toUtf8, latin1_toUtf16, 1 },
{ VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 },
{
#include "asciitab.h"
#include "latin1tab.h"
@ -245,7 +245,7 @@ void ascii_toUtf8(const ENCODING *enc,
}
static const struct normal_encoding ascii_encoding = {
{ VTABLE1, ascii_toUtf8, latin1_toUtf16, 1 },
{ VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 },
{
#include "asciitab.h"
/* BT_NONXML == 0 */
@ -384,7 +384,13 @@ DEFINE_UTF16_TO_UTF16
#undef IS_INVALID_CHAR
static const struct normal_encoding little2_encoding = {
{ VTABLE, 2 },
{ VTABLE, 2, 0,
#if BYTE_ORDER == 12
1
#else
0
#endif
},
#include "asciitab.h"
#include "latin1tab.h"
};
@ -392,7 +398,7 @@ static const struct normal_encoding little2_encoding = {
#if BYTE_ORDER != 21
static const struct normal_encoding internal_little2_encoding = {
{ VTABLE, 2 },
{ VTABLE, 2, 0, 1 },
#include "iasciitab.h"
#include "latin1tab.h"
};
@ -437,7 +443,13 @@ DEFINE_UTF16_TO_UTF16
#undef IS_INVALID_CHAR
static const struct normal_encoding big2_encoding = {
{ VTABLE, 2 },
{ VTABLE, 2, 0,
#if BYTE_ORDER == 21
1
#else
0
#endif
},
#include "asciitab.h"
#include "latin1tab.h"
};
@ -445,7 +457,7 @@ static const struct normal_encoding big2_encoding = {
#if BYTE_ORDER != 12
static const struct normal_encoding internal_big2_encoding = {
{ VTABLE, 2 },
{ VTABLE, 2, 0, 1 },
#include "iasciitab.h"
#include "latin1tab.h"
};

View file

@ -159,6 +159,8 @@ struct encoding {
unsigned short **toP,
const unsigned short *toLim);
int minBytesPerChar;
char isUtf8;
char isUtf16;
};
/*