ICU-11761 share equal strings even if they need explicit length; more generic root resource for flexibility (experiment with more work on pool bundles)
X-SVN-Rev: 37649
This commit is contained in:
parent
18e27b35d6
commit
f87b2c9b3c
@ -565,10 +565,9 @@ processFile(const char *filename, const char *cp,
|
||||
goto finish;
|
||||
}
|
||||
if(options[WRITE_POOL_BUNDLE].doesOccur) {
|
||||
int32_t newKeysLength;
|
||||
const char *newKeys, *newKeysLimit;
|
||||
data->compactKeys(*status);
|
||||
newKeys = data->getKeyBytes(&newKeysLength);
|
||||
int32_t newKeysLength;
|
||||
const char *newKeys = data->getKeyBytes(&newKeysLength);
|
||||
newPoolBundle->addKeyBytes(newKeys, newKeysLength, *status);
|
||||
if(U_FAILURE(*status)) {
|
||||
fprintf(stderr, "bundle_compactKeys(%s) or bundle_getKeyBytes() failed: %s\n",
|
||||
@ -576,7 +575,7 @@ processFile(const char *filename, const char *cp,
|
||||
goto finish;
|
||||
}
|
||||
/* count the number of just-added key strings */
|
||||
for(newKeysLimit = newKeys + newKeysLength; newKeys < newKeysLimit; ++newKeys) {
|
||||
for(const char *newKeysLimit = newKeys + newKeysLength; newKeys < newKeysLimit; ++newKeys) {
|
||||
if(*newKeys == 0) {
|
||||
++newPoolBundle->fKeysCount;
|
||||
}
|
||||
|
@ -2046,9 +2046,12 @@ parse(UCHARBUF *buf, const char *inputDir, const char *outputDir, const char *fi
|
||||
state.bundle->fNoFallback=TRUE;
|
||||
}
|
||||
/* top-level tables need not handle special table names like "collations" */
|
||||
realParseTable(&state, state.bundle->fRoot, NULL, line, status);
|
||||
assert(!state.bundle->fIsPoolBundle);
|
||||
assert(state.bundle->fRoot->fType == URES_TABLE);
|
||||
TableResource *rootTable = static_cast<TableResource *>(state.bundle->fRoot);
|
||||
realParseTable(&state, rootTable, NULL, line, status);
|
||||
if(dependencyArray!=NULL){
|
||||
state.bundle->fRoot->add(dependencyArray, 0, *status);
|
||||
rootTable->add(dependencyArray, 0, *status);
|
||||
dependencyArray = NULL;
|
||||
}
|
||||
if (U_FAILURE(*status))
|
||||
|
@ -1002,7 +1002,7 @@ struct SResource *bin_open(struct SRBRoot *bundle, const char *tag, uint32_t len
|
||||
|
||||
SRBRoot::SRBRoot(const UString *comment, UBool isPoolBundle, UErrorCode &errorCode)
|
||||
: fRoot(NULL), fLocale(NULL), fIndexLength(0), fMaxTableLength(0), fNoFallback(FALSE),
|
||||
fStringsForm(0), fIsPoolBundle(FALSE),
|
||||
fStringsForm(0), fIsPoolBundle(isPoolBundle),
|
||||
fKeys(NULL), fKeyMap(NULL),
|
||||
fKeysBottom(0), fKeysTop(0), fKeysCapacity(0), fKeysCount(0), fLocalKeyLimit(0),
|
||||
f16BitUnits(), f16BitStringsLength(0),
|
||||
@ -1022,7 +1022,6 @@ SRBRoot::SRBRoot(const UString *comment, UBool isPoolBundle, UErrorCode &errorCo
|
||||
|
||||
fKeysCapacity = KEY_SPACE_SIZE;
|
||||
/* formatVersion 1.1: start fKeysTop after the root item and indexes[] */
|
||||
fIsPoolBundle = isPoolBundle;
|
||||
if (gUsePoolBundle || isPoolBundle) {
|
||||
fIndexLength = URES_INDEX_POOL_CHECKSUM + 1;
|
||||
} else if (gFormatVersion >= 2) {
|
||||
@ -1417,9 +1416,9 @@ SRBRoot::compactStringsV2(UHashtable *stringSet, UErrorCode &errorCode) {
|
||||
int32_t j;
|
||||
for (j = i + 1; j < count; ++j) {
|
||||
StringResource *suffixRes = array[j];
|
||||
/* Is it a suffix of the earlier, longer key? */
|
||||
/* Is it a suffix of the earlier, longer string? */
|
||||
if (res->fString.endsWith(suffixRes->fString)) {
|
||||
if (suffixRes->fNumCharsForLength == 0) {
|
||||
if (suffixRes->fNumCharsForLength == 0 || res->length() == suffixRes->length()) {
|
||||
/* yes, point to the earlier string */
|
||||
suffixRes->fSame = res;
|
||||
suffixRes->fSuffixOffset = res->length() - suffixRes->length();
|
||||
@ -1449,12 +1448,17 @@ SRBRoot::compactStringsV2(UHashtable *stringSet, UErrorCode &errorCode) {
|
||||
}
|
||||
if (f16BitUnits.isBogus()) {
|
||||
errorCode = U_MEMORY_ALLOCATION_ERROR;
|
||||
return;
|
||||
}
|
||||
/* Write the suffix strings. Make each point to the real string. */
|
||||
for (; i < count; ++i) {
|
||||
StringResource *res = array[i];
|
||||
StringResource *same = res->fSame;
|
||||
if (res->length() == same->length()) {
|
||||
res->fRes = same->fRes;
|
||||
} else {
|
||||
res->fRes = same->fRes + same->fNumCharsForLength + res->fSuffixOffset;
|
||||
}
|
||||
res->fSame = NULL;
|
||||
res->fWritten = TRUE;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ struct ResFile {
|
||||
int32_t fChecksum;
|
||||
};
|
||||
|
||||
class TableResource;
|
||||
struct SResource;
|
||||
|
||||
typedef struct KeyMapEntry {
|
||||
int32_t oldpos, newpos;
|
||||
@ -83,7 +83,7 @@ private:
|
||||
public:
|
||||
// TODO: private
|
||||
|
||||
TableResource *fRoot;
|
||||
SResource *fRoot; // Normally a TableResource.
|
||||
char *fLocale;
|
||||
int32_t fIndexLength;
|
||||
int32_t fMaxTableLength;
|
||||
@ -124,6 +124,7 @@ void bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char*
|
||||
struct SResource* res_none(void);
|
||||
|
||||
class ArrayResource;
|
||||
class TableResource;
|
||||
class IntVectorResource;
|
||||
|
||||
TableResource *table_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status);
|
||||
|
Loading…
Reference in New Issue
Block a user