From 932759f00a750bb9c488d22265394f15612f39b1 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Sat, 30 Sep 2006 22:35:25 +0000 Subject: [PATCH] ICU-5426 Make it easier to change the size of the converter hash table depending on the platform. X-SVN-Rev: 20464 --- icu4c/source/common/ucnv_bld.c | 14 +++++++++++++- icu4c/source/common/ucnv_io.c | 4 ++-- icu4c/source/common/ucnv_io.h | 5 ++--- icu4c/source/common/uinit.c | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/icu4c/source/common/ucnv_bld.c b/icu4c/source/common/ucnv_bld.c index 62e1609f08..b4bf90174f 100644 --- a/icu4c/source/common/ucnv_bld.c +++ b/icu4c/source/common/ucnv_bld.c @@ -363,6 +363,15 @@ getAlgorithmicTypeFromName(const char *realName) return NULL; } +/* +* Based on the number of known converters, this determines how many times larger +* the shared data hash table should be. When on small platforms, or just a couple +* of converters are used, this number should be 2. When memory is plentiful, or +* when ucnv_countAvailable is ever used, this should be 4. +* Larger numbers reduce the number of hash collisions, but use more memory. +*/ +#define UCNV_CACHE_LOAD_FACTOR 4 + /* Puts the shared data in the static hashtable SHARED_DATA_HASHTABLE */ /* Will always be called with the cnvCacheMutex alrady being held */ /* by the calling function. */ @@ -379,7 +388,7 @@ ucnv_shareConverterData(UConverterSharedData * data) if (SHARED_DATA_HASHTABLE == NULL) { SHARED_DATA_HASHTABLE = uhash_openSize(uhash_hashChars, uhash_compareChars, NULL, - ucnv_io_countTotalAliases(&err), + ucnv_io_countKnownConverters(&err)*UCNV_CACHE_LOAD_FACTOR, &err); ucln_common_registerCleanup(UCLN_COMMON_UCNV, ucnv_cleanup); @@ -1040,6 +1049,9 @@ static UBool haveAvailableConverterList(UErrorCode *pErrorCode) { return FALSE; } + /* Open the default converter to make sure that it has first dibs in the hash table. */ + ucnv_close(ucnv_createConverter(&tempConverter, NULL, &localStatus)); + localConverterCount = 0; for (idx = 0; idx < allConverterCount; idx++) { diff --git a/icu4c/source/common/ucnv_io.c b/icu4c/source/common/ucnv_io.c index 4e570e55d9..8af52ce987 100644 --- a/icu4c/source/common/ucnv_io.c +++ b/icu4c/source/common/ucnv_io.c @@ -1069,9 +1069,9 @@ ucnv_openAllNames(UErrorCode *pErrorCode) { } U_CFUNC uint16_t -ucnv_io_countTotalAliases(UErrorCode *pErrorCode) { +ucnv_io_countKnownConverters(UErrorCode *pErrorCode) { if (haveAliasData(pErrorCode)) { - return (uint16_t)gMainTable.aliasListSize; + return (uint16_t)gMainTable.converterListSize; } return 0; } diff --git a/icu4c/source/common/ucnv_io.h b/icu4c/source/common/ucnv_io.h index 91bc6e5916..060ffd0595 100644 --- a/icu4c/source/common/ucnv_io.h +++ b/icu4c/source/common/ucnv_io.h @@ -95,13 +95,12 @@ U_CFUNC const char * ucnv_io_getConverterName(const char *alias, UBool *containsOption, UErrorCode *pErrorCode); /** - * Return the number of all aliases and converter names. - * This is helpful if you need a number for creating an alias table. + * Return the number of all known converter names (no aliases). * @param pErrorCode The error code * @return the number of all aliases */ U_CFUNC uint16_t -ucnv_io_countTotalAliases(UErrorCode *pErrorCode); +ucnv_io_countKnownConverters(UErrorCode *pErrorCode); /** * Swap an ICU converter alias table. See implementation for details. diff --git a/icu4c/source/common/uinit.c b/icu4c/source/common/uinit.c index a70e51d0e6..56b686b365 100644 --- a/icu4c/source/common/uinit.c +++ b/icu4c/source/common/uinit.c @@ -85,7 +85,7 @@ u_init(UErrorCode *status) { * available. */ #if !UCONFIG_NO_CONVERSION - ucnv_io_countTotalAliases(status); + ucnv_io_countKnownConverters(status); #endif #else /* Do any required init for services that don't have open operations