static void setMissingPropertiesToDefault( RepXCollection& collection, RepXReaderWriter& editor, const RepXDefaultEntry* defaults, PxU32 numDefaults ) { FoundationWrapper wrapper( collection.getAllocator() ); //Release all strings at once, instead of piece by piece RepXMemoryAllocatorImpl alloc( collection.getAllocator() ); //build a hashtable of the initial default value strings. TNameOffsetMap nameOffsets( wrapper ); for ( PxU32 idx = 0; idx < numDefaults; ++idx ) { const RepXDefaultEntry& item( defaults[idx] ); size_t nameLen = 0; const char* periodPtr = nextPeriod (item.name); for ( ; periodPtr && *periodPtr; ++periodPtr ) if( *periodPtr == '.' ) break; if ( periodPtr == NULL || *periodPtr != '.' ) continue; nameLen = periodPtr - item.name; char* newMem = (char*)alloc.allocate( PxU32(nameLen + 1) ); memcpy( newMem, item.name, nameLen ); newMem[nameLen] = 0; if ( nameOffsets.find( newMem ) ) alloc.deallocate( (PxU8*)newMem ); else nameOffsets.insert( newMem, idx ); } //Run through each collection item, and recursively find it and its children //If an object's name is in the hash map, check and add any properties that don't exist. //else return. for ( const RepXCollectionItem* item = collection.begin(), *end = collection.end(); item != end; ++ item ) { RepXCollectionItem theItem( *item ); setMissingPropertiesToDefault( theItem.mDescriptor, editor, defaults, numDefaults, nameOffsets ); } }
void buildValueMap(const Value values[], int32_t length, UErrorCode &errorCode) { UVector32 sortedValues(errorCode); UVector32 nameOffsets(errorCode); // Parallel to values[]. int32_t i; for(i=0; i<length; ++i) { sortedValues.sortedInsert(values[i].enumValue, errorCode); nameOffsets.addElement(writeValueAliases(values[i], errorCode), errorCode); } int32_t ranges[10][2]; int32_t numRanges=uprv_makeDenseRanges(sortedValues.getBuffer(), length, 0xe0, ranges, LENGTHOF(ranges)); if(numRanges>0) { valueMaps.addElement(numRanges, errorCode); for(i=0; i<numRanges; ++i) { valueMaps.addElement(ranges[i][0], errorCode); valueMaps.addElement(ranges[i][1]+1, errorCode); for(int32_t j=ranges[i][0]; j<=ranges[i][1]; ++j) { // The range might not be completely dense, so j might not have an entry, // in which case we write a nameOffset of 0. // Real nameOffsets for property values are never 0. // (The first name group is for the first property name.) int32_t valueIndex=valuesIndexOf(values, length, j); int32_t nameOffset= valueIndex>=0 ? nameOffsets.elementAti(valueIndex) : 0; valueMaps.addElement(nameOffset, errorCode); } } } else { // No dense ranges. valueMaps.addElement(0x10+length, errorCode); for(i=0; i<length; ++i) { valueMaps.addElement(sortedValues.elementAti(i), errorCode); } for(i=0; i<length; ++i) { valueMaps.addElement( nameOffsets.elementAti( valuesIndexOf(values, length, sortedValues.elementAti(i))), errorCode); } } }