ICU-4425 Remove the getTerminatedBuffer Purify warning, and speed up timezone creation to offset any performance hits.

X-SVN-Rev: 17282
This commit is contained in:
George Rhoten 2005-03-03 23:46:10 +00:00
parent 40536bd2fa
commit 3f0a1edf15
2 changed files with 33 additions and 34 deletions

View file

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (c) 2003-2004, International Business Machines
* Copyright (c) 2003-2005, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Author: Alan Liu
@ -97,7 +97,7 @@ OlsonTimeZone::OlsonTimeZone(const UResourceBundle* top,
// Size 4 is like size 3, but with an alias list at the end
// Size 5 is a hybrid zone, with historical and final elements
// Size 6 is like size 5, but with an alias list at the end
int32_t size = ures_getSize((UResourceBundle*) res); // cast away const
int32_t size = ures_getSize(res);
if (size < 3 || size > 6) {
ec = U_INVALID_FORMAT_ERROR;
}
@ -106,23 +106,21 @@ OlsonTimeZone::OlsonTimeZone(const UResourceBundle* top,
int32_t i;
UResourceBundle* r = ures_getByIndex(res, 0, NULL, &ec);
transitionTimes = ures_getIntVector(r, &i, &ec);
ures_close(r);
if ((i<0 || i>0x7FFF) && U_SUCCESS(ec)) {
ec = U_INVALID_FORMAT_ERROR;
}
transitionCount = (int16_t) i;
// Type offsets list must be of even size, with size >= 2
r = ures_getByIndex(res, 1, NULL, &ec);
r = ures_getByIndex(res, 1, r, &ec);
typeOffsets = ures_getIntVector(r, &i, &ec);
ures_close(r);
if ((i<2 || i>0x7FFE || ((i&1)!=0)) && U_SUCCESS(ec)) {
ec = U_INVALID_FORMAT_ERROR;
}
typeCount = (int16_t) i >> 1;
// Type data must be of the same size as the transitions list
r = ures_getByIndex(res, 2, NULL, &ec);
r = ures_getByIndex(res, 2, r, &ec);
int32_t len;
typeData = ures_getBinary(r, &len, &ec);
ures_close(r);

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. *
*******************************************************************************
*
@ -179,38 +179,39 @@ static UBool getOlsonMeta() {
static int32_t findInStringArray(UResourceBundle* array, const UnicodeString& id, UErrorCode &status)
{
UnicodeString copy;
copy.fastCopyFrom(id);
const UChar* buf = copy.getTerminatedBuffer();
const UChar* u = NULL;
int32_t count = ures_getSize(array);
int32_t start = 0;
int32_t i;
const UChar *u;
int32_t len;
int32_t limit = count;
if(U_FAILURE(status) || (count < 1)) {
int32_t start = 0;
int32_t limit = ures_getSize(array);
int32_t mid;
int32_t lastMid = INT32_MAX;
if(U_FAILURE(status) || (limit < 1)) {
return -1;
}
U_DEBUG_TZ_MSG(("fisa: Looking for %s, between %d and %d\n", U_DEBUG_TZ_STR(buf), start, limit));
U_DEBUG_TZ_MSG(("fisa: Looking for %s, between %d and %d\n", U_DEBUG_TZ_STR(UnicodeString(id).getTerminatedBuffer()), start, limit));
while(U_SUCCESS(status) && (start<limit-1)) {
i = (int32_t)((start+limit)/2);
u = ures_getStringByIndex(array, i, &len, &status);
U_DEBUG_TZ_MSG(("tz: compare to %s, %d .. [%d] .. %d\n", U_DEBUG_TZ_STR(u), start, i, limit));
int r = u_strcmp(buf,u);
if((r==0) && U_SUCCESS(status)) {
U_DEBUG_TZ_MSG(("fisa: found at %d\n", i));
return i;
} else if(r<0) {
limit = i;
} else {
start = i;
for (;;) {
mid = (int32_t)((start + limit) / 2);
if (lastMid == mid) { /* Have we moved? */
break; /* We haven't moved, and it wasn't found. */
}
lastMid = mid;
u = ures_getStringByIndex(array, mid, &len, &status);
if (U_FAILURE(status)) {
break;
}
U_DEBUG_TZ_MSG(("tz: compare to %s, %d .. [%d] .. %d\n", U_DEBUG_TZ_STR(u), start, mid, limit));
copy.setTo(TRUE, u, len);
int r = id.compare(copy);
if(r==0) {
U_DEBUG_TZ_MSG(("fisa: found at %d\n", mid));
return mid;
} else if(r<0) {
limit = mid;
} else {
start = mid;
}
}
u = ures_getStringByIndex(array, start, &len, &status);
if(u_strcmp(buf,u)==0) {
U_DEBUG_TZ_MSG(("fisa: finally found at %d\n", start));
return start;
}
U_DEBUG_TZ_MSG(("fisa: not found\n"));
return -1;