ICU-2120 Improve the performance of some functions.
X-SVN-Rev: 11184
This commit is contained in:
parent
7cad3c755f
commit
2a1a26d193
@ -54,9 +54,10 @@ T_CString_toUpperCase(char* str)
|
||||
return origPtr;
|
||||
}
|
||||
|
||||
/*Takes a int32_t and fills in a char* string with that number "radix"-based*/
|
||||
/*Takes a int32_t and fills in a char* string with that number "radix"-based
|
||||
Return the length of the string */
|
||||
|
||||
U_CAPI void U_EXPORT2
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
T_CString_integerToString(char* buffer, int32_t i, int32_t radix)
|
||||
{
|
||||
int32_t length=0;
|
||||
@ -83,7 +84,7 @@ T_CString_integerToString(char* buffer, int32_t i, int32_t radix)
|
||||
buffer[i] = temp;
|
||||
}
|
||||
|
||||
return;
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
|
@ -69,7 +69,7 @@ T_CString_toLowerCase(char* str);
|
||||
U_CAPI char* U_EXPORT2
|
||||
T_CString_toUpperCase(char* str);
|
||||
|
||||
U_CAPI void U_EXPORT2
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
T_CString_integerToString(char *buffer, int32_t n, int32_t radix);
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
|
@ -855,17 +855,18 @@ _startsWith(const char *s, const char *possiblePrefix) {
|
||||
* mechanism is desired, one could move variant display strings into their
|
||||
* own table "Variants" like the Languages and Countries tables.
|
||||
*/
|
||||
static UResourceBundle *
|
||||
_res_getTableItemWithFallback(const char *path, const char *locale,
|
||||
static const UChar *
|
||||
_res_getTableStringWithFallback(const char *path, const char *locale,
|
||||
const char *tableKey, const char *itemKey,
|
||||
UResourceBundle **pMainRB,
|
||||
UErrorCode *pErrorCode) {
|
||||
int32_t *pLength,
|
||||
UErrorCode *pErrorCode)
|
||||
{
|
||||
char localeBuffer[200];
|
||||
UResourceBundle *rb, *table, *item;
|
||||
UResourceBundle *rb, table;
|
||||
const UChar *item;
|
||||
const char *defaultLocale;
|
||||
UBool lookedAtDefault;
|
||||
|
||||
*pMainRB=NULL;
|
||||
lookedAtDefault=FALSE;
|
||||
defaultLocale=uloc_getDefault();
|
||||
|
||||
@ -904,6 +905,7 @@ _res_getTableItemWithFallback(const char *path, const char *locale,
|
||||
locale=ures_getLocale(rb, pErrorCode);
|
||||
if(U_FAILURE(*pErrorCode)) {
|
||||
/* error getting the locale ID for an open RB - should never happen */
|
||||
*pErrorCode=U_INTERNAL_PROGRAM_ERROR;
|
||||
ures_close(rb);
|
||||
return NULL;
|
||||
}
|
||||
@ -916,7 +918,8 @@ _res_getTableItemWithFallback(const char *path, const char *locale,
|
||||
* this falls back through the locale's chain to root, but not through the default locale
|
||||
*/
|
||||
*pErrorCode=U_ZERO_ERROR;
|
||||
table=ures_getByKey(rb, tableKey, NULL, pErrorCode);
|
||||
ures_initStackObject(&table);
|
||||
ures_getByKey(rb, tableKey, &table, pErrorCode);
|
||||
if(U_FAILURE(*pErrorCode)) {
|
||||
/* no such table anywhere in this fallback chain */
|
||||
ures_close(rb);
|
||||
@ -952,29 +955,33 @@ _res_getTableItemWithFallback(const char *path, const char *locale,
|
||||
#endif
|
||||
|
||||
/* get the real locale ID for this table in case of aliases & fallbacks */
|
||||
locale=ures_getLocale(table, pErrorCode);
|
||||
locale=ures_getLocale(&table, pErrorCode);
|
||||
if(U_FAILURE(*pErrorCode)) {
|
||||
/* error getting the locale ID for an open RB - should never happen */
|
||||
ures_close(table);
|
||||
*pErrorCode=U_INTERNAL_PROGRAM_ERROR;
|
||||
ures_close(&table);
|
||||
ures_close(rb);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(itemKey!=NULL) {
|
||||
/* try to open the requested item in the table */
|
||||
item=ures_getByKey(table, itemKey, NULL, pErrorCode);
|
||||
ures_close(table); /* we will not need the table any more */
|
||||
item=ures_getStringByKey(&table, itemKey, pLength, pErrorCode);
|
||||
if(U_SUCCESS(*pErrorCode)) {
|
||||
/* we got the requested item! */
|
||||
*pMainRB=rb;
|
||||
ures_close(&table);
|
||||
ures_close(rb);
|
||||
return item;
|
||||
}
|
||||
} else {
|
||||
/* return the "table" resource itself, not an item from it */
|
||||
*pMainRB=rb;
|
||||
return table;
|
||||
item=ures_getString(&table, pLength, pErrorCode);
|
||||
ures_close(&table); /* we will not need the table any more */
|
||||
ures_close(rb);
|
||||
return item;
|
||||
}
|
||||
|
||||
ures_close(&table);
|
||||
ures_close(rb);
|
||||
if(lookedAtDefault && (*locale==0 || 0==uprv_strcmp(locale, "root"))) {
|
||||
/* end of fallback, default and root do not have the requested item either */
|
||||
@ -1005,27 +1012,21 @@ _getStringOrCopyKey(const char *path, const char *locale,
|
||||
const char *substitute,
|
||||
UChar *dest, int32_t destCapacity,
|
||||
UErrorCode *pErrorCode) {
|
||||
UResourceBundle *rb, *item;
|
||||
const UChar *s;
|
||||
int32_t length;
|
||||
|
||||
length=-1;
|
||||
item=_res_getTableItemWithFallback(path, locale,
|
||||
s=_res_getTableStringWithFallback(path, locale,
|
||||
tableKey, itemKey,
|
||||
&rb,
|
||||
&length,
|
||||
pErrorCode);
|
||||
if(U_SUCCESS(*pErrorCode)) {
|
||||
s=ures_getString(item, &length, pErrorCode);
|
||||
if(U_SUCCESS(*pErrorCode)) {
|
||||
int32_t copyLength=uprv_min(length, destCapacity);
|
||||
if(copyLength>0) {
|
||||
u_memcpy(dest, s, copyLength);
|
||||
}
|
||||
} else {
|
||||
length=-1;
|
||||
if(U_SUCCESS(*pErrorCode) && s) {
|
||||
int32_t copyLength=uprv_min(length, destCapacity);
|
||||
if(copyLength>0) {
|
||||
u_memcpy(dest, s, copyLength);
|
||||
}
|
||||
ures_close(item);
|
||||
ures_close(rb);
|
||||
} else {
|
||||
length=-1;
|
||||
}
|
||||
|
||||
/* no string from a resource bundle: convert the substitute */
|
||||
|
@ -661,16 +661,16 @@ static UResourceBundle *init_resb_result(const ResourceData *rdata, Resource r,
|
||||
resB->fKey = key;
|
||||
ures_freeResPath(resB);
|
||||
if(parent->fResPath) {
|
||||
ures_appendResPath(resB, parent->fResPath);
|
||||
ures_appendResPath(resB, parent->fResPath, parent->fResPathLen);
|
||||
}
|
||||
if(key != NULL) {
|
||||
ures_appendResPath(resB, key);
|
||||
ures_appendResPath(resB, RES_PATH_SEPARATOR_S);
|
||||
ures_appendResPath(resB, key, uprv_strlen(key));
|
||||
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1);
|
||||
} else {
|
||||
char buf[256];
|
||||
T_CString_integerToString(buf, index, 10);
|
||||
ures_appendResPath(resB, buf);
|
||||
ures_appendResPath(resB, RES_PATH_SEPARATOR_S);
|
||||
int32_t len = T_CString_integerToString(buf, index, 10);
|
||||
ures_appendResPath(resB, buf, len);
|
||||
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1);
|
||||
}
|
||||
|
||||
resB->fVersion = NULL;
|
||||
@ -715,7 +715,7 @@ UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *origin
|
||||
uprv_memcpy(r, original, sizeof(UResourceBundle));
|
||||
r->fResPath = NULL;
|
||||
if(original->fResPath) {
|
||||
ures_appendResPath(r, original->fResPath);
|
||||
ures_appendResPath(r, original->fResPath, original->fResPathLen);
|
||||
}
|
||||
ures_setIsStackObject(r, isStackObject);
|
||||
if(r->fData != NULL) {
|
||||
@ -1321,13 +1321,14 @@ U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd) {
|
||||
uprv_strcpy(resB->fResPath, toAdd);
|
||||
}
|
||||
*/
|
||||
U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd) {
|
||||
U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd) {
|
||||
int32_t resPathLenOrig = resB->fResPathLen;
|
||||
if(resB->fResPath == NULL) {
|
||||
resB->fResPath = resB->fResBuf;
|
||||
*(resB->fResPath) = 0;
|
||||
resB->fResPathLen = 0;
|
||||
}
|
||||
resB->fResPathLen += uprv_strlen(toAdd);
|
||||
resB->fResPathLen += lenToAdd;
|
||||
if(RES_BUFSIZE <= resB->fResPathLen+1) {
|
||||
if(resB->fResPath == resB->fResBuf) {
|
||||
resB->fResPath = (char *)uprv_malloc((resB->fResPathLen+1)*sizeof(char));
|
||||
@ -1336,7 +1337,7 @@ U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd) {
|
||||
resB->fResPath = (char *)uprv_realloc(resB->fResPath, (resB->fResPathLen+1)*sizeof(char));
|
||||
}
|
||||
}
|
||||
uprv_strcat(resB->fResPath, toAdd);
|
||||
uprv_strcpy(resB->fResPath + resPathLenOrig, toAdd);
|
||||
}
|
||||
|
||||
U_CFUNC void ures_freeResPath(UResourceBundle *resB) {
|
||||
|
@ -59,16 +59,15 @@ struct UResourceDataEntry {
|
||||
|
||||
struct UResourceBundle {
|
||||
const char *fKey; /*tag*/
|
||||
UResourceDataEntry *fData; /*for low-level access*/
|
||||
char *fVersion;
|
||||
char *fResPath; /* full path to the resource: "zh_TW/CollationElements/Sequence" */
|
||||
char fResBuf[RES_BUFSIZE];
|
||||
int32_t fResPathLen;
|
||||
char *fVersion;
|
||||
UBool fHasFallback;
|
||||
UBool fIsTopLevel;
|
||||
uint32_t fMagic1;
|
||||
uint32_t fMagic2;
|
||||
/*UBool fIsStackObject;*/
|
||||
UResourceDataEntry *fData; /*for low-level access*/
|
||||
uint32_t fMagic1; /* For determining if it's a stack object */
|
||||
uint32_t fMagic2; /* For determining if it's a stack object */
|
||||
int32_t fIndex;
|
||||
int32_t fSize;
|
||||
ResourceData fResData;
|
||||
@ -88,7 +87,7 @@ U_CFUNC UBool ures_isStackObject( UResourceBundle* resB);
|
||||
/* Some getters used by the copy constructor */
|
||||
U_CFUNC const char* ures_getName(const UResourceBundle* resB);
|
||||
U_CFUNC const char* ures_getPath(const UResourceBundle* resB);
|
||||
U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd);
|
||||
U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd);
|
||||
/*U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd);*/
|
||||
U_CFUNC void ures_freeResPath(UResourceBundle *resB);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user