ICU-5225 Minor speed improvement for opening and closing converters.

X-SVN-Rev: 19705
This commit is contained in:
George Rhoten 2006-06-12 06:28:31 +00:00
parent 290c62fdcd
commit b6fa95c973
3 changed files with 51 additions and 39 deletions

View File

@ -1,7 +1,7 @@
/*
******************************************************************************
*
* Copyright (C) 1998-2005, International Business Machines
* Copyright (C) 1998-2006, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
@ -295,27 +295,6 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
U_CAPI void U_EXPORT2
ucnv_close (UConverter * converter)
{
/* first, notify the callback functions that the converter is closed */
UConverterToUnicodeArgs toUArgs = {
sizeof(UConverterToUnicodeArgs),
TRUE,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
UConverterFromUnicodeArgs fromUArgs = {
sizeof(UConverterFromUnicodeArgs),
TRUE,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
UErrorCode errorCode = U_ZERO_ERROR;
UTRACE_ENTRY_OC(UTRACE_UCNV_CLOSE);
@ -329,11 +308,41 @@ ucnv_close (UConverter * converter)
UTRACE_DATA3(UTRACE_OPEN_CLOSE, "close converter %s at %p, isCopyLocal=%b",
ucnv_getName(converter, &errorCode), converter, converter->isCopyLocal);
toUArgs.converter = fromUArgs.converter = converter;
/* In order to speed up the close, only call the callbacks when they have been changed.
This performance check will only work when the callbacks are set within a shared library
or from user code that statically links this code. */
/* first, notify the callback functions that the converter is closed */
if (converter->fromCharErrorBehaviour != UCNV_TO_U_DEFAULT_CALLBACK) {
UConverterToUnicodeArgs toUArgs = {
sizeof(UConverterToUnicodeArgs),
TRUE,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
converter->fromCharErrorBehaviour(converter->toUContext, &toUArgs, NULL, 0, UCNV_CLOSE, &errorCode);
errorCode = U_ZERO_ERROR;
converter->fromUCharErrorBehaviour(converter->fromUContext, &fromUArgs, NULL, 0, 0, UCNV_CLOSE, &errorCode);
toUArgs.converter = converter;
errorCode = U_ZERO_ERROR;
converter->fromCharErrorBehaviour(converter->toUContext, &toUArgs, NULL, 0, UCNV_CLOSE, &errorCode);
}
if (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_CLOSE, &errorCode);
}
if (converter->sharedData->impl->close != NULL) {
converter->sharedData->impl->close(converter);
@ -349,7 +358,7 @@ ucnv_close (UConverter * converter)
}
if(!converter->isCopyLocal){
uprv_free (converter);
uprv_free(converter);
}
UTRACE_EXIT();

View File

@ -1,7 +1,7 @@
/*
********************************************************************
* COPYRIGHT:
* Copyright (c) 1996-2005, International Business Machines Corporation and
* Copyright (c) 1996-2006, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************
*
@ -878,20 +878,20 @@ ucnv_createConverterFromSharedData(UConverter *myUConverter,
/* initialize the converter */
uprv_memset(myUConverter, 0, sizeof(UConverter));
myUConverter->isCopyLocal = isCopyLocal;
myUConverter->isExtraLocal = FALSE;
/*myUConverter->isExtraLocal = FALSE;*/ /* Set by the memset call */
myUConverter->sharedData = mySharedConverterData;
myUConverter->options = options;
myUConverter->fromCharErrorBehaviour = (UConverterToUCallback) UCNV_TO_U_CALLBACK_SUBSTITUTE;
myUConverter->fromUCharErrorBehaviour = (UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE;
myUConverter->toUnicodeStatus = myUConverter->sharedData->toUnicodeStatus;
myUConverter->maxBytesPerUChar = myUConverter->sharedData->staticData->maxBytesPerChar;
myUConverter->subChar1 = myUConverter->sharedData->staticData->subChar1;
myUConverter->subCharLen = myUConverter->sharedData->staticData->subCharLen;
uprv_memcpy (myUConverter->subChar, myUConverter->sharedData->staticData->subChar, myUConverter->subCharLen);
myUConverter->preFromUFirstCP = U_SENTINEL;
myUConverter->fromCharErrorBehaviour = UCNV_TO_U_DEFAULT_CALLBACK;
myUConverter->fromUCharErrorBehaviour = UCNV_FROM_U_DEFAULT_CALLBACK;
myUConverter->toUnicodeStatus = mySharedConverterData->toUnicodeStatus;
myUConverter->maxBytesPerUChar = mySharedConverterData->staticData->maxBytesPerChar;
myUConverter->subChar1 = mySharedConverterData->staticData->subChar1;
myUConverter->subCharLen = mySharedConverterData->staticData->subCharLen;
uprv_memcpy(myUConverter->subChar, mySharedConverterData->staticData->subChar, myUConverter->subCharLen);
if(myUConverter != NULL && myUConverter->sharedData->impl->open != NULL) {
myUConverter->sharedData->impl->open(myUConverter, realName, locale,options, err);
if(myUConverter != NULL && mySharedConverterData->impl->open != NULL) {
mySharedConverterData->impl->open(myUConverter, realName, locale,options, err);
if(U_FAILURE(*err)) {
ucnv_close(myUConverter);
return NULL;

View File

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (C) 1999-2005, International Business Machines
* Copyright (C) 1999-2006, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*
@ -87,6 +87,9 @@ ucnv_unloadSharedDataIfReady(UConverterSharedData *sharedData);
void
ucnv_incrementRefCount(UConverterSharedData *sharedData);
#define UCNV_TO_U_DEFAULT_CALLBACK ((UConverterToUCallback) UCNV_TO_U_CALLBACK_SUBSTITUTE)
#define UCNV_FROM_U_DEFAULT_CALLBACK ((UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE)
#endif
#endif /* _UCNV_IMP */