ICU-6112 Reset a converter about 20% faster. This is helpful when converting many small strings. In the overall scheme of things, it's not that significant since a reset is generally quick.

X-SVN-Rev: 23137
This commit is contained in:
George Rhoten 2007-12-28 19:59:17 +00:00
parent 10611e82fd
commit da6bcd2c16
2 changed files with 29 additions and 24 deletions

View file

@ -565,34 +565,35 @@ static void _reset(UConverter *converter, UConverterResetChoice choice,
if(callCallback) {
/* first, notify the callback functions that the converter is reset */
UConverterToUnicodeArgs toUArgs = {
sizeof(UConverterToUnicodeArgs),
TRUE,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
UConverterFromUnicodeArgs fromUArgs = {
sizeof(UConverterFromUnicodeArgs),
TRUE,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
UErrorCode errorCode;
toUArgs.converter = fromUArgs.converter = converter;
if(choice<=UCNV_RESET_TO_UNICODE) {
if(choice<=UCNV_RESET_TO_UNICODE && converter->fromCharErrorBehaviour != UCNV_TO_U_DEFAULT_CALLBACK) {
UConverterToUnicodeArgs toUArgs = {
sizeof(UConverterToUnicodeArgs),
TRUE,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
toUArgs.converter = converter;
errorCode = U_ZERO_ERROR;
converter->fromCharErrorBehaviour(converter->toUContext, &toUArgs, NULL, 0, UCNV_RESET, &errorCode);
}
if(choice!=UCNV_RESET_TO_UNICODE) {
if(choice!=UCNV_RESET_TO_UNICODE && converter->fromUCharErrorBehaviour != UCNV_FROM_U_DEFAULT_CALLBACK) {
UConverterFromUnicodeArgs fromUArgs = {
sizeof(UConverterFromUnicodeArgs),
TRUE,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
fromUArgs.converter = converter;
errorCode = U_ZERO_ERROR;
converter->fromUCharErrorBehaviour(converter->fromUContext, &fromUArgs, NULL, 0, 0, UCNV_RESET, &errorCode);
}

View file

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (C) 1999-2006, International Business Machines
* Copyright (C) 1999-2007, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*
@ -87,6 +87,10 @@ ucnv_unloadSharedDataIfReady(UConverterSharedData *sharedData);
void
ucnv_incrementRefCount(UConverterSharedData *sharedData);
/**
* These are the default error handling callbacks for the charset conversion framework.
* For performance reasons, they are only called to handle an error (not normally called for a reset or close).
*/
#define UCNV_TO_U_DEFAULT_CALLBACK ((UConverterToUCallback) UCNV_TO_U_CALLBACK_SUBSTITUTE)
#define UCNV_FROM_U_DEFAULT_CALLBACK ((UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE)