From 1384c72211ff2b2b5dcae1cee551d41d3b51c14d Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Fri, 10 Aug 2012 16:41:38 +0000 Subject: [PATCH] ICU-9456 Reduce writable/relocatable data. X-SVN-Rev: 32149 --- icu4c/source/common/uloc_tag.c | 29 +++++++++++++++-------------- icu4c/source/common/usprep.cpp | 8 ++++---- icu4c/source/i18n/alphaindex.cpp | 2 +- icu4c/source/i18n/csrsbcs.cpp | 4 ++-- icu4c/source/i18n/ucol_bld.cpp | 9 +++++---- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/icu4c/source/common/uloc_tag.c b/icu4c/source/common/uloc_tag.c index d62346f27f8..a0ea97d722e 100644 --- a/icu4c/source/common/uloc_tag.c +++ b/icu4c/source/common/uloc_tag.c @@ -17,6 +17,8 @@ #include "ulocimp.h" #include "uassert.h" +#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) + /* struct holding a single variant */ typedef struct VariantListEntry { const char *variant; @@ -62,19 +64,19 @@ typedef struct ULanguageTag { #define ISALPHA(c) uprv_isASCIILetter(c) #define ISNUMERIC(c) ((c)>='0' && (c)<='9') -static const char* EMPTY = ""; -static const char* LANG_UND = "und"; -static const char* PRIVATEUSE_KEY = "x"; -static const char* _POSIX = "_POSIX"; -static const char* POSIX_KEY = "va"; -static const char* POSIX_VALUE = "posix"; -static const char* LOCALE_ATTRIBUTE_KEY = "attribute"; -static const char* PRIVUSE_VARIANT_PREFIX = "lvariant"; -static const char* LOCALE_TYPE_YES = "yes"; +static const char EMPTY[] = ""; +static const char LANG_UND[] = "und"; +static const char PRIVATEUSE_KEY[] = "x"; +static const char _POSIX[] = "_POSIX"; +static const char POSIX_KEY[] = "va"; +static const char POSIX_VALUE[] = "posix"; +static const char LOCALE_ATTRIBUTE_KEY[] = "attribute"; +static const char PRIVUSE_VARIANT_PREFIX[] = "lvariant"; +static const char LOCALE_TYPE_YES[] = "yes"; #define LANG_UND_LEN 3 -static const char* GRANDFATHERED[] = { +static const char* const GRANDFATHERED[] = { /* grandfathered preferred */ "art-lojban", "jbo", "cel-gaulish", "xtg-x-cel-gaulish", @@ -105,12 +107,11 @@ static const char* GRANDFATHERED[] = { NULL, NULL }; -static const char* DEPRECATEDLANGS[] = { +static const char DEPRECATEDLANGS[][4] = { /* deprecated new */ "iw", "he", "ji", "yi", - "in", "id", - NULL, NULL + "in", "id" }; /* @@ -1028,7 +1029,7 @@ _appendLanguageToLanguageTag(const char* localeID, char* appendAt, int32_t capac reslen += LANG_UND_LEN; } else { /* resolve deprecated */ - for (i = 0; DEPRECATEDLANGS[i] != NULL; i += 2) { + for (i = 0; i < LENGTHOF(DEPRECATEDLANGS); i += 2) { if (uprv_compareInvCharsAsAscii(buf, DEPRECATEDLANGS[i]) == 0) { uprv_strcpy(buf, DEPRECATEDLANGS[i + 1]); len = (int32_t)uprv_strlen(buf); diff --git a/icu4c/source/common/usprep.cpp b/icu4c/source/common/usprep.cpp index 415253c332e..925ed38b717 100644 --- a/icu4c/source/common/usprep.cpp +++ b/icu4c/source/common/usprep.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * - * Copyright (C) 2003-2010, International Business Machines + * Copyright (C) 2003-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -46,13 +46,13 @@ static UHashtable *SHARED_DATA_HASHTABLE = NULL; static UMTX usprepMutex = NULL; /* format version of spp file */ -static uint8_t formatVersion[4]={ 0, 0, 0, 0 }; +//static uint8_t formatVersion[4]={ 0, 0, 0, 0 }; /* the Unicode version of the sprep data */ static UVersionInfo dataVersion={ 0, 0, 0, 0 }; /* Profile names must be aligned to UStringPrepProfileType */ -static const char *PROFILE_NAMES[] = { +static const char * const PROFILE_NAMES[] = { "rfc3491", /* USPREP_RFC3491_NAMEPREP */ "rfc3530cs", /* USPREP_RFC3530_NFS4_CS_PREP */ "rfc3530csci", /* USPREP_RFC3530_NFS4_CS_PREP_CI */ @@ -86,7 +86,7 @@ isSPrepAcceptable(void * /* context */, pInfo->formatVersion[2]==UTRIE_SHIFT && pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT ) { - uprv_memcpy(formatVersion, pInfo->formatVersion, 4); + //uprv_memcpy(formatVersion, pInfo->formatVersion, 4); uprv_memcpy(dataVersion, pInfo->dataVersion, 4); return TRUE; } else { diff --git a/icu4c/source/i18n/alphaindex.cpp b/icu4c/source/i18n/alphaindex.cpp index fadc2f42a62..cf51a03fe4e 100644 --- a/icu4c/source/i18n/alphaindex.cpp +++ b/icu4c/source/i18n/alphaindex.cpp @@ -861,7 +861,7 @@ UVector *AlphabeticIndex::firstStringsInScript(Collator *ruleBasedCollator, UErr // Character constants copied from corresponding declaration in ICU4J. // See main/classes/collate/src/com/ibm/icu/text/AlphabeticIndex.java -static UChar HACK_FIRST_CHARS_IN_SCRIPTS[] = { 0x61, 0, 0x03B1, 0, +static const UChar HACK_FIRST_CHARS_IN_SCRIPTS[] = { 0x61, 0, 0x03B1, 0, 0x2C81, 0, 0x0430, 0, 0x2C30, 0, 0x10D0, 0, 0x0561, 0, 0x05D0, 0, 0xD802, 0xDD00, 0, 0x0800, 0, 0x0621, 0, 0x0710, 0, 0x0780, 0, 0x07CA, 0, 0x2D30, 0, 0x1200, 0, 0x0950, 0, 0x0985, 0, 0x0A74, 0, 0x0AD0, 0, 0x0B05, 0, 0x0BD0, 0, 0x0C05, 0, 0x0C85, 0, 0x0D05, 0, 0x0D85, 0, diff --git a/icu4c/source/i18n/csrsbcs.cpp b/icu4c/source/i18n/csrsbcs.cpp index 4c387c7d634..1aad70e39ae 100644 --- a/icu4c/source/i18n/csrsbcs.cpp +++ b/icu4c/source/i18n/csrsbcs.cpp @@ -1164,7 +1164,7 @@ uint8_t *CharsetRecog_IBM420_ar::unshapeLamAlef(const uint8_t *inputBytes, int32 if (bigBuffer != NULL) { int32_t bufferIndex; - uint8_t unshapedLamAlef[] = { 0xb1, 0x56 }; + static const uint8_t unshapedLamAlef[] = { 0xb1, 0x56 }; for (int32_t i = bufferIndex = 0; i < inputBytesLength; i++) { if (isLamAlef(inputBytes[i])) { @@ -1199,7 +1199,7 @@ void CharsetRecog_IBM420_ar::matchFinish(InputText *textIn) { } UBool CharsetRecog_IBM420_ar::isLamAlef(uint8_t b) { - uint8_t shapedLamAlef[] = { + static const uint8_t shapedLamAlef[] = { 0xb2, 0xb3, 0xb4, 0xb5, 0xb7, 0xb8 }; diff --git a/icu4c/source/i18n/ucol_bld.cpp b/icu4c/source/i18n/ucol_bld.cpp index 566812b1aba..d51118f978a 100644 --- a/icu4c/source/i18n/ucol_bld.cpp +++ b/icu4c/source/i18n/ucol_bld.cpp @@ -37,6 +37,8 @@ #include "cmemory.h" #include "cstring.h" +#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) + static const InverseUCATableHeader* _staticInvUCA = NULL; static UDataMemory* invUCA_DATA_MEM = NULL; @@ -1393,13 +1395,12 @@ ucol_initInverseUCA(UErrorCode *status) /* This is the data that is used for non-script reordering codes. These _must_ be kept * in order that they are to be applied as defaults and in synch with the UColReorderCode enum. */ -static const char* ReorderingTokenNames[] = { +static const char * const ReorderingTokenNames[] = { "SPACE", "PUNCT", "SYMBOL", "CURRENCY", - "DIGIT", - NULL + "DIGIT" }; static void toUpper(const char* src, char* dst, uint32_t length) { @@ -1413,7 +1414,7 @@ U_INTERNAL int32_t U_EXPORT2 ucol_findReorderingEntry(const char* name) { char buffer[32]; toUpper(name, buffer, 32); - for (uint32_t entry = 0; ReorderingTokenNames[entry] != NULL; entry++) { + for (uint32_t entry = 0; entry < LENGTHOF(ReorderingTokenNames); entry++) { if (uprv_strcmp(buffer, ReorderingTokenNames[entry]) == 0) { return entry + UCOL_REORDER_CODE_FIRST; }