const LSR **supportedLSRs, int32_t supportedLSRsLength,
int32_t shiftedThreshold,
ULocMatchFavorSubtag favorSubtag, ULocMatchDirection direction) const {
- // Round up the shifted threshold (if fraction bits are not 0)
- // for comparison with un-shifted distances until we need fraction bits.
- // (If we simply shifted non-zero fraction bits away, then we might ignore a language
- // when it's really still a micro distance below the threshold.)
- int32_t roundedThreshold = (shiftedThreshold + DISTANCE_FRACTION_MASK) >> DISTANCE_SHIFT;
BytesTrie iter(trie);
// Look up the desired language only once for all supported LSRs.
// Its "distance" is either a match point value of 0, or a non-match negative value.
star = true;
}
U_ASSERT(0 <= distance && distance <= 100);
+ // Round up the shifted threshold (if fraction bits are not 0)
+ // for comparison with un-shifted distances until we need fraction bits.
+ // (If we simply shifted non-zero fraction bits away, then we might ignore a language
+ // when it's really still a micro distance below the threshold.)
+ int32_t roundedThreshold = (shiftedThreshold + DISTANCE_FRACTION_MASK) >> DISTANCE_SHIFT;
// We implement "favor subtag" by reducing the language subtag distance
// (unscientifically reducing it to a quarter of the normal value),
// so that the script distance is relatively more important.
if (favorSubtag == ULOCMATCH_FAVOR_SCRIPT) {
distance >>= 2;
}
- if (distance >= roundedThreshold) {
+ // Let distance == roundedThreshold pass until the tie-breaker logic
+ // at the end of the loop.
+ if (distance > roundedThreshold) {
continue;
}
scriptDistance &= ~DISTANCE_IS_FINAL;
}
distance += scriptDistance;
- if (distance >= roundedThreshold) {
+ if (distance > roundedThreshold) {
continue;
}
distance += defaultRegionDistance;
} else {
int32_t remainingThreshold = roundedThreshold - distance;
- if (minRegionDistance >= remainingThreshold) {
+ if (minRegionDistance > remainingThreshold) {
continue;
}
d = getFallbackRegionDistance(iter, startState);
star = true;
}
- if (d >= threshold) {
+ if (d > threshold) {
return d;
} else if (regionDistance < d) {
regionDistance = d;
}
} else if (!star) {
int32_t d = getFallbackRegionDistance(iter, startState);
- if (d >= threshold) {
+ if (d > threshold) {
return d;
} else if (regionDistance < d) {
regionDistance = d;
*/
public int getBestIndexAndDistance(LSR desired, LSR[] supportedLSRs, int supportedLSRsLength,
int shiftedThreshold, FavorSubtag favorSubtag, LocaleMatcher.Direction direction) {
- // Round up the shifted threshold (if fraction bits are not 0)
- // for comparison with un-shifted distances until we need fraction bits.
- // (If we simply shifted non-zero fraction bits away, then we might ignore a language
- // when it's really still a micro distance below the threshold.)
- int roundedThreshold = (shiftedThreshold + DISTANCE_FRACTION_MASK) >> DISTANCE_SHIFT;
BytesTrie iter = new BytesTrie(trie);
// Look up the desired language only once for all supported LSRs.
// Its "distance" is either a match point value of 0, or a non-match negative value.
star = true;
}
assert 0 <= distance && distance <= 100;
+ // Round up the shifted threshold (if fraction bits are not 0)
+ // for comparison with un-shifted distances until we need fraction bits.
+ // (If we simply shifted non-zero fraction bits away, then we might ignore a language
+ // when it's really still a micro distance below the threshold.)
+ int roundedThreshold = (shiftedThreshold + DISTANCE_FRACTION_MASK) >> DISTANCE_SHIFT;
// We implement "favor subtag" by reducing the language subtag distance
// (unscientifically reducing it to a quarter of the normal value),
// so that the script distance is relatively more important.
if (favorSubtag == FavorSubtag.SCRIPT) {
distance >>= 2;
}
- if (distance >= roundedThreshold) {
+ // Let distance == roundedThreshold pass until the tie-breaker logic
+ // at the end of the loop.
+ if (distance > roundedThreshold) {
continue;
}
scriptDistance &= ~DISTANCE_IS_FINAL;
}
distance += scriptDistance;
- if (distance >= roundedThreshold) {
+ if (distance > roundedThreshold) {
continue;
}
distance += defaultRegionDistance;
} else {
int remainingThreshold = roundedThreshold - distance;
- if (minRegionDistance >= remainingThreshold) {
+ if (minRegionDistance > remainingThreshold) {
continue;
}
d = getFallbackRegionDistance(iter, startState);
star = true;
}
- if (d >= threshold) {
+ if (d > threshold) {
return d;
} else if (regionDistance < d) {
regionDistance = d;
}
} else if (!star) {
int d = getFallbackRegionDistance(iter, startState);
- if (d >= threshold) {
+ if (d > threshold) {
return d;
} else if (regionDistance < d) {
regionDistance = d;