/* preallocate and reset the first data block (block index 0) */
j=UTRIE_DATA_BLOCK_LENGTH;
if(latin1Linear) { /* preallocate and reset the first block (number 0) and Latin-1 (U+0000..U+00ff) after that */ /* made sure above that maxDataLength>=1024 */
/* set indexes to point to consecutive data blocks */
i=0; do { /* do this at least for trie->index[0] even if that block is only partly used for Latin-1 */
trie->index[i++]=j;
j+=UTRIE_DATA_BLOCK_LENGTH;
} while(i<(256>>UTRIE_SHIFT));
}
/* reset the initially allocated blocks to the initial value */
trie->dataLength=j; while(j>0) {
trie->data[--j]=initialValue;
}
newBlock=trie->dataLength;
newTop=newBlock+UTRIE_DATA_BLOCK_LENGTH; if(newTop>trie->dataCapacity) { /* out of memory in the data array */ return -1;
}
trie->dataLength=newTop; return newBlock;
}
/* allocate a new data block */
newBlock=utrie_allocDataBlock(trie); if(newBlock<0) { /* out of memory in the data array */ return -1;
}
trie->index[c]=newBlock;
/* copy-on-write for a block from a setRange() */
uprv_memcpy(trie->data+newBlock, trie->data-indexValue, 4*UTRIE_DATA_BLOCK_LENGTH); return newBlock;
}
/* number of positions in the last, partial block */
rest=limit&UTRIE_MASK;
/* round down limit to a block boundary */
limit&=~UTRIE_MASK;
/* iterate over all-value blocks */ if(value==initialValue) {
repeatBlock=0;
} else {
repeatBlock=-1;
} while(start<limit) { /* get index value */
block=trie->index[start>>UTRIE_SHIFT]; if(block>0) { /* already allocated, fill in value */
utrie_fillBlock(trie->data+block, 0, UTRIE_DATA_BLOCK_LENGTH, value, initialValue, overwrite);
} elseif(trie->data[-block]!=value && (block==0 || overwrite)) { /* set the repeatBlock instead of the current block 0 or range block */ if(repeatBlock>=0) {
trie->index[start>>UTRIE_SHIFT]=-repeatBlock;
} else { /* create and set and fill the repeatBlock */
repeatBlock=utrie_getDataBlock(trie, start); if(repeatBlock<0) { returnfalse;
}
/* set the negative block number to indicate that it is a repeat block */
trie->index[start>>UTRIE_SHIFT]=-repeatBlock;
utrie_fillBlock(trie->data+repeatBlock, 0, UTRIE_DATA_BLOCK_LENGTH, value, initialValue, true);
}
}
start+=UTRIE_DATA_BLOCK_LENGTH;
}
if(rest>0) { /* set partial block at [last block boundary..limit[ */
block=utrie_getDataBlock(trie, start); if(block<0) { returnfalse;
}
/* search for any index (stage 1) entries for supplementary code points */ for(c=0x10000; c<0x110000;) { if(idx[c>>UTRIE_SHIFT]!=0) { /* there is data, treat the full block for a lead surrogate */
c&=~0x3ff;
#ifdef UTRIE_DEBUG
++countLeadCUWithData; /* printf("supplementary data for lead surrogate U+%04lx\n", (long)(0xd7c0+(c>>10))); */ #endif
/* is there an identical index block? */
block=_findSameIndexBlock(idx, indexLength, c>>UTRIE_SHIFT);
/* if we did not find an identical index block... */ if(block==indexLength) { /* move the actual index (stage 1) entries from the supplementary position to the new one */
uprv_memmove(idx+indexLength,
idx+(c>>UTRIE_SHIFT), 4*UTRIE_SURROGATE_BLOCK_COUNT);
indexLength+=UTRIE_SURROGATE_BLOCK_COUNT;
}
}
c+=0x400;
} else {
c+=UTRIE_DATA_BLOCK_LENGTH;
}
} #ifdef UTRIE_DEBUG if(countLeadCUWithData>0) {
printf("supplementary data for %d lead surrogates\n", countLeadCUWithData);
} #endif
/* valid, uncompacted trie? */ if(trie==nullptr) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; return;
} if(trie->isCompacted) { return; /* nothing left to do */
}
/* compaction */
/* initialize the index map with "block is used/unused" flags */
_findUnusedBlocks(trie);
/* if Latin-1 is preallocated and linear, then do not compact Latin-1 data */ if(trie->isLatin1Linear && UTRIE_SHIFT<=8) {
overlapStart=UTRIE_DATA_BLOCK_LENGTH+256;
} else {
overlapStart=UTRIE_DATA_BLOCK_LENGTH;
}
/* skip blocks that are not used */ if(trie->map[start>>UTRIE_SHIFT]<0) { /* advance start to the next block */
start+=UTRIE_DATA_BLOCK_LENGTH;
/* leave newStart with the previous block! */ continue;
}
/* search for an identical block */ if( start>=overlapStart &&
(i=_findSameDataBlock(trie->data, newStart, start,
overlap ? UTRIE_DATA_GRANULARITY : UTRIE_DATA_BLOCK_LENGTH))
>=0
) { /* found an identical block, set the other block's index value for the current block */
trie->map[start>>UTRIE_SHIFT]=i;
/* advance start to the next block */
start+=UTRIE_DATA_BLOCK_LENGTH;
/* leave newStart with the previous block! */ continue;
}
/* see if the beginning of this block can be overlapped with the end of the previous block */ if(overlap && start>=overlapStart) { /* look for maximum overlap (modulo granularity) with the previous, adjacent block */ for(i=UTRIE_DATA_BLOCK_LENGTH-UTRIE_DATA_GRANULARITY;
i>0 && !equal_uint32(trie->data+(newStart-i), trie->data+start, i);
i-=UTRIE_DATA_GRANULARITY) {}
} else {
i=0;
}
if(i>0) { /* some overlap */
trie->map[start>>UTRIE_SHIFT]=newStart-i;
/* move the non-overlapping indexes to their new positions */
start+=i; for(i=UTRIE_DATA_BLOCK_LENGTH-i; i>0; --i) {
trie->data[newStart++]=trie->data[start++];
}
} elseif(newStart<start) { /* no overlap, just move the indexes to their new positions */
trie->map[start>>UTRIE_SHIFT]=newStart; for(i=UTRIE_DATA_BLOCK_LENGTH; i>0; --i) {
trie->data[newStart++]=trie->data[start++];
}
} else/* no overlap && newStart==start */ {
trie->map[start>>UTRIE_SHIFT]=start;
newStart+=UTRIE_DATA_BLOCK_LENGTH;
start=newStart;
}
}
/* now adjust the index (stage 1) table */ for(i=0; i<trie->indexLength; ++i) {
trie->index[i]=trie->map[ABS(trie->index[i])>>UTRIE_SHIFT];
}
#ifdef UTRIE_DEBUG /* we saved some space */
printf("compacting trie: count of 32-bit words %lu->%lu\n",
(long)trie->dataLength, (long)newStart); #endif
data = (uint8_t*)dt; /* fold and compact if necessary, also checks that indexLength is within limits */ if(!trie->isCompacted) { /* compact once without overlap to improve folding */
utrie_compact(trie, false, pErrorCode);
/* fold the supplementary part of the index array */
utrie_fold(trie, getFoldedValue, pErrorCode);
/* compact again with overlap for minimum data array length */
utrie_compact(trie, true, pErrorCode);
/* write the index (stage 1) array and the 16/32-bit data (stage 2) array */ if(reduceTo16Bits) { /* write 16-bit index values shifted right by UTRIE_INDEX_SHIFT, after adding indexLength */
p=(uint32_t *)trie->index;
dest16=(uint16_t *)data; for(i=trie->indexLength; i>0; --i) {
*dest16++=(uint16_t)((*p++ + trie->indexLength)>>UTRIE_INDEX_SHIFT);
}
/* write 16-bit data values */
p=trie->data; for(i=trie->dataLength; i>0; --i) {
*dest16++=(uint16_t)*p++;
}
} else { /* write 16-bit index values shifted right by UTRIE_INDEX_SHIFT */
p=(uint32_t *)trie->index;
dest16=(uint16_t *)data; for(i=trie->indexLength; i>0; --i) {
*dest16++=(uint16_t)(*p++ >> UTRIE_INDEX_SHIFT);
}
/* write 32-bit data values */
uprv_memcpy(dest16, trie->data, 4*(size_t)trie->dataLength);
}
/* get the options and check the shift values */
options=header->options; if( (options&UTRIE_OPTIONS_SHIFT_MASK)!=UTRIE_SHIFT ||
((options>>UTRIE_OPTIONS_INDEX_SHIFT)&UTRIE_OPTIONS_SHIFT_MASK)!=UTRIE_INDEX_SHIFT
) {
*pErrorCode=U_INVALID_FORMAT_ERROR; return -1;
}
trie->isLatin1Linear = (options & UTRIE_OPTIONS_LATIN1_IS_LINEAR) != 0;
/* get the length values */
trie->indexLength=header->indexLength;
trie->dataLength=header->dataLength;
length-=(int32_t)sizeof(UTrieHeader);
/* enough data for the index? */ if(length<2*trie->indexLength) {
*pErrorCode=U_INVALID_FORMAT_ERROR; return -1;
}
p16=(const uint16_t *)(header+1);
trie->index=p16;
p16+=trie->indexLength;
length-=2*trie->indexLength;
/* get the data */ if(options&UTRIE_OPTIONS_DATA_IS_32_BIT) { if(length<4*trie->dataLength) {
*pErrorCode=U_INVALID_FORMAT_ERROR; return -1;
}
trie->data32=(const uint32_t *)p16;
trie->initialValue=trie->data32[0];
length=(int32_t)sizeof(UTrieHeader)+2*trie->indexLength+4*trie->dataLength;
} else { if(length<2*trie->dataLength) {
*pErrorCode=U_INVALID_FORMAT_ERROR; return -1;
}
/* the "data16" data is used via the index pointer */
trie->data32=nullptr;
trie->initialValue=trie->index[trie->indexLength];
length=(int32_t)sizeof(UTrieHeader)+2*trie->indexLength+2*trie->dataLength;
}
if(leadUnitValue!=initialValue) { /* indexes for lead surrogate code units to the block after Latin-1 */
block+=(uint16_t)(latin1Length>>UTRIE_INDEX_SHIFT);
i=0xd800>>UTRIE_SHIFT;
limit=0xdc00>>UTRIE_SHIFT; for(; i<limit; ++i) {
p16[i]=block;
}
}
/* data for lead surrogate code units */ if(leadUnitValue!=initialValue) {
limit=latin1Length+UTRIE_DATA_BLOCK_LENGTH; for(/* i=latin1Length */; i<limit; ++i) {
p16[i]=(uint16_t)leadUnitValue;
}
}
} else {
uint32_t *p32;
/* indexes to block 0 */
uprv_memset(p16, 0, trie->indexLength*2);
if(leadUnitValue!=initialValue) { /* indexes for lead surrogate code units to the block after Latin-1 */
block=(uint16_t)(latin1Length>>UTRIE_INDEX_SHIFT);
i=0xd800>>UTRIE_SHIFT;
limit=0xdc00>>UTRIE_SHIFT; for(; i<limit; ++i) {
p16[i]=block;
}
}
/* set variables for previous range */
prevBlock=nullBlock;
prev=0;
prevValue=initialValue;
/* enumerate BMP - the main loop enumerates data blocks */ for(i=0, c=0; c<=0xffff; ++i) { if(c==0xd800) { /* skip lead surrogate code _units_, go to lead surr. code _points_ */
i=UTRIE_BMP_INDEX_LENGTH;
} elseif(c==0xdc00) { /* go back to regular BMP code points */
i=c>>UTRIE_SHIFT;
}
block=idx[i]<<UTRIE_INDEX_SHIFT; if(block==prevBlock) { /* the block is the same as the previous one, and filled with value */
c+=UTRIE_DATA_BLOCK_LENGTH;
} elseif(block==nullBlock) { /* this is the all-initial-value block */ if(prevValue!=initialValue) { if(prev<c) { if(!enumRange(context, prev, c, prevValue)) { return;
}
}
prevBlock=nullBlock;
prev=c;
prevValue=initialValue;
}
c+=UTRIE_DATA_BLOCK_LENGTH;
} else {
prevBlock=block; for(j=0; j<UTRIE_DATA_BLOCK_LENGTH; ++j) {
value=enumValue(context, data32!=nullptr ? data32[block+j] : idx[block+j]); if(value!=prevValue) { if(prev<c) { if(!enumRange(context, prev, c, prevValue)) { return;
}
} if(j>0) { /* the block is not filled with all the same value */
prevBlock=-1;
}
prev=c;
prevValue=value;
}
++c;
}
}
}
/* enumerate supplementary code points */ for(l=0xd800; l<0xdc00;) { /* lead surrogate access */
offset=idx[l>>UTRIE_SHIFT]<<UTRIE_INDEX_SHIFT; if(offset==nullBlock) { /* no entries for a whole block of lead surrogates */ if(prevValue!=initialValue) { if(prev<c) { if(!enumRange(context, prev, c, prevValue)) { return;
}
}
prevBlock=nullBlock;
prev=c;
prevValue=initialValue;
}
/* enumerate trail surrogates for this lead surrogate */
offset=trie->getFoldingOffset(value); if(offset<=0) { /* no data for this lead surrogate */ if(prevValue!=initialValue) { if(prev<c) { if(!enumRange(context, prev, c, prevValue)) { return;
}
}
prevBlock=nullBlock;
prev=c;
prevValue=initialValue;
}
/* nothing else to do for the supplementary code points for this lead surrogate */
c+=0x400;
} else { /* enumerate code points for this lead surrogate */
i=offset;
offset+=UTRIE_SURROGATE_BLOCK_COUNT; do { /* copy of most of the body of the BMP loop */
block=idx[i]<<UTRIE_INDEX_SHIFT; if(block==prevBlock) { /* the block is the same as the previous one, and filled with value */
c+=UTRIE_DATA_BLOCK_LENGTH;
} elseif(block==nullBlock) { /* this is the all-initial-value block */ if(prevValue!=initialValue) { if(prev<c) { if(!enumRange(context, prev, c, prevValue)) { return;
}
}
prevBlock=nullBlock;
prev=c;
prevValue=initialValue;
}
c+=UTRIE_DATA_BLOCK_LENGTH;
} else {
prevBlock=block; for(j=0; j<UTRIE_DATA_BLOCK_LENGTH; ++j) {
value=enumValue(context, data32!=nullptr ? data32[block+j] : idx[block+j]); if(value!=prevValue) { if(prev<c) { if(!enumRange(context, prev, c, prevValue)) { return;
}
} if(j>0) { /* the block is not filled with all the same value */
prevBlock=-1;
}
prev=c;
prevValue=value;
}
++c;
}
}
} while(++i<offset);
}
++l;
}
/* deliver last range */
enumRange(context, prev, c, prevValue);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.21 Sekunden
(vorverarbeitet am 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.