ICU-4425 Remove the uninitialized memory copy Purify warning, and speed up resource bundle traversal to offset any performance hits.

X-SVN-Rev: 17336
This commit is contained in:
George Rhoten 2005-03-15 00:03:58 +00:00
parent ad1723db06
commit d860f22457
2 changed files with 82 additions and 68 deletions

View file

@ -1,6 +1,6 @@
/*
******************************************************************************
* Copyright (C) 1997-2004, International Business Machines Corporation and *
* Copyright (C) 1997-2005, International Business Machines Corporation and *
* others. All Rights Reserved. *
******************************************************************************
*
@ -267,7 +267,7 @@ static UResourceDataEntry *init_entry(const char *localeID, const char *path, UE
/* here we try to deduce the right locale name */
if(localeID == NULL) { /* if localeID is NULL, we're trying to open default locale */
uprv_strcpy(name, uloc_getDefault());
} else if(uprv_strlen(localeID) == 0) { /* if localeID is "" then we try to open root locale */
} else if(*localeID == 0) { /* if localeID is "" then we try to open root locale */
uprv_strcpy(name, kRootLocaleName);
} else { /* otherwise, we'll open what we're given */
uprv_strcpy(name, localeID);
@ -338,18 +338,20 @@ static UResourceDataEntry *init_entry(const char *localeID, const char *path, UE
/* handle the alias by trying to get out the %%Alias tag.*/
/* We'll try to get alias string from the bundle */
Resource aliasres = res_getResource(&(r->fData), "%%ALIAS");
const UChar *alias = res_getString(&(r->fData), aliasres, &aliasLen);
if(alias != NULL && aliasLen > 0) { /* if there is actual alias - unload and load new data */
u_UCharsToChars(alias, aliasName, aliasLen+1);
isAlias = TRUE;
res_unload(&(r->fData));
result = res_load(&(r->fData), r->fPath, aliasName, status);
if (result == FALSE || U_FAILURE(*status)) {
/* we couldn't load aliased data - so we have no data */
*status = U_USING_FALLBACK_WARNING;
r->fBogus = U_USING_FALLBACK_WARNING;
if (aliasres != RES_BOGUS) {
const UChar *alias = res_getString(&(r->fData), aliasres, &aliasLen);
if(alias != NULL && aliasLen > 0) { /* if there is actual alias - unload and load new data */
u_UCharsToChars(alias, aliasName, aliasLen+1);
isAlias = TRUE;
res_unload(&(r->fData));
result = res_load(&(r->fData), r->fPath, aliasName, status);
if (result == FALSE || U_FAILURE(*status)) {
/* we couldn't load aliased data - so we have no data */
*status = U_USING_FALLBACK_WARNING;
r->fBogus = U_USING_FALLBACK_WARNING;
}
setEntryName(r, aliasName, status);
}
setEntryName(r, aliasName, status);
}
}
@ -806,16 +808,21 @@ static UResourceBundle *init_resb_result(const ResourceData *rdata, Resource r,
resB->fParentRes = parent;
resB->fTopLevelData = parent->fTopLevelData;
if(parent->fResPath && parent != resB) {
ures_appendResPath(resB, parent->fResPath, parent->fResPathLen);
ures_appendResPath(resB, parent->fResPath, parent->fResPathLen);
}
if(key != NULL) {
ures_appendResPath(resB, key, (int32_t)uprv_strlen(key));
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1);
ures_appendResPath(resB, key, (int32_t)uprv_strlen(key));
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1);
} else {
char buf[256];
int32_t len = T_CString_integerToString(buf, index, 10);
ures_appendResPath(resB, buf, len);
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1);
char buf[256];
int32_t len = T_CString_integerToString(buf, index, 10);
ures_appendResPath(resB, buf, len);
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1);
}
/* Make sure that Purify doesn't complain about uninitialized memory copies. */
{
int32_t unusedLen = ((resB->fResBuf == resB->fResPath) ? resB->fResPathLen : 0);
uprv_memset(resB->fResBuf + unusedLen, 0, sizeof(resB->fResBuf) - unusedLen);
}
resB->fVersion = NULL;
@ -1301,7 +1308,7 @@ ures_findSubResource(const UResourceBundle *resB, char* path, UResourceBundle *f
*status = U_MISSING_RESOURCE_ERROR;
break;
}
} while(uprv_strlen(path)); /* there is more stuff in the path */
} while(*path); /* there is more stuff in the path */
return result;
}

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
* *
* Copyright (C) 1999-2004, International Business Machines Corporation *
* Copyright (C) 1999-2005, International Business Machines Corporation *
* and others. All Rights Reserved. *
* *
*******************************************************************************
@ -119,72 +119,79 @@ static Resource
_res_findTableItem(const Resource *pRoot, const Resource res, const char *key,
int32_t *index, const char **realKey) {
const uint16_t *p=(const uint16_t *)RES_GET_POINTER(pRoot, res);
int32_t i, start, limit;
uint32_t mid, start, limit;
uint32_t lastMid;
int result;
limit=*p++; /* number of entries */
if(limit == 0) { /* this table is empty */
*index=URESDATA_ITEM_NOT_FOUND;
return RES_BOGUS;
}
if(limit != 0) {
/* do a binary search for the key */
start=0;
lastMid = UINT32_MAX;
for (;;) {
mid = (uint32_t)((start + limit) / 2);
if (lastMid == mid) { /* Have we moved? */
break; /* We haven't moved, and it wasn't found. */
}
lastMid = mid;
result = uprv_strcmp(key, RES_GET_KEY(pRoot, p[mid]));
/* do a binary search for the key */
start=0;
while(start<limit-1) {
i=(int32_t)((start+limit)/2);
if(uprv_strcmp(key, RES_GET_KEY(pRoot, p[i]))<0) {
limit=i;
} else {
start=i;
if (result < 0) {
limit = mid;
} else if (result > 0) {
start = mid;
} else {
/* We found it! */
*index=mid;
*realKey=RES_GET_KEY(pRoot, p[mid]);
limit=*(p-1); /* itemCount */
return ((const Resource *)(p+limit+(~limit&1)))[mid];
}
}
}
/* did we really find it? */
if(uprv_strcmp(key, RES_GET_KEY(pRoot, p[start]))==0) {
*index=start;
*realKey=RES_GET_KEY(pRoot, p[start]);
limit=*(p-1); /* itemCount */
return ((const Resource *)(p+limit+(~limit&1)))[start];
} else {
*index=URESDATA_ITEM_NOT_FOUND;
return RES_BOGUS; /* not found */
}
*index=URESDATA_ITEM_NOT_FOUND;
return RES_BOGUS; /* not found or table is empty. */
}
static Resource
_res_findTable32Item(const Resource *pRoot, const Resource res, const char *key,
int32_t *index, const char **realKey) {
const int32_t *p=(const int32_t *)RES_GET_POINTER(pRoot, res);
int32_t i, start, limit;
int32_t mid, start, limit;
int32_t lastMid;
int result;
limit=*p++; /* number of entries */
if(limit == 0) { /* this table is empty */
*index=URESDATA_ITEM_NOT_FOUND;
return RES_BOGUS;
}
if(limit != 0) {
/* do a binary search for the key */
start=0;
lastMid = INT32_MAX;
for (;;) {
mid = (uint32_t)((start + limit) / 2);
if (lastMid == mid) { /* Have we moved? */
break; /* We haven't moved, and it wasn't found. */
}
lastMid = mid;
result = uprv_strcmp(key, RES_GET_KEY(pRoot, p[mid]));
/* do a binary search for the key */
start=0;
while(start<limit-1) {
i=(int32_t)((start+limit)/2);
if(uprv_strcmp(key, RES_GET_KEY(pRoot, p[i]))<0) {
limit=i;
} else {
start=i;
if (result < 0) {
limit = mid;
} else if (result > 0) {
start = mid;
} else {
/* We found it! */
*index=mid;
*realKey=RES_GET_KEY(pRoot, p[mid]);
return ((const Resource *)(p+(*(p-1))))[mid];
}
}
}
/* did we really find it? */
if(uprv_strcmp(key, RES_GET_KEY(pRoot, p[start]))==0) {
*index=start;
*realKey=RES_GET_KEY(pRoot, p[start]);
limit=*(p-1); /* itemCount */
return ((const Resource *)(p+limit))[start];
} else {
*index=URESDATA_ITEM_NOT_FOUND;
return RES_BOGUS; /* not found */
}
*index=URESDATA_ITEM_NOT_FOUND;
return RES_BOGUS; /* not found or table is empty. */
}
/* helper for res_load() ---------------------------------------------------- */