mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-20916 UBSan & ErrorProne fixes
This commit is contained in:
parent
ad638c274e
commit
cb1d4f5903
4 changed files with 22 additions and 13 deletions
|
@ -103,7 +103,7 @@ int32_t LSR::indexForRegion(const char *region) {
|
|||
|
||||
LSR &LSR::setHashCode() {
|
||||
if (hashCode == 0) {
|
||||
int32_t h = ustr_hashCharsN(language, static_cast<int32_t>(uprv_strlen(language)));
|
||||
uint32_t h = ustr_hashCharsN(language, static_cast<int32_t>(uprv_strlen(language)));
|
||||
h = h * 37 + ustr_hashCharsN(script, static_cast<int32_t>(uprv_strlen(script)));
|
||||
h = h * 37 + regionIndex;
|
||||
hashCode = h * 37 + flags;
|
||||
|
|
|
@ -173,7 +173,7 @@ public class LocaleDistance {
|
|||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) { return true; }
|
||||
if (!getClass().equals(other.getClass())) { return false; }
|
||||
if (other == null || !getClass().equals(other.getClass())) { return false; }
|
||||
Data od = (Data)other;
|
||||
return Arrays.equals(trie, od.trie) &&
|
||||
Arrays.equals(regionToPartitionsIndex, od.regionToPartitionsIndex) &&
|
||||
|
@ -181,6 +181,11 @@ public class LocaleDistance {
|
|||
paradigmLSRs.equals(od.paradigmLSRs) &&
|
||||
Arrays.equals(distances, od.distances);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() { // unused; silence ErrorProne
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// VisibleForTesting
|
||||
|
|
|
@ -97,7 +97,7 @@ public final class XLikelySubtags {
|
|||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) { return true; }
|
||||
if (!getClass().equals(other.getClass())) { return false; }
|
||||
if (other == null || !getClass().equals(other.getClass())) { return false; }
|
||||
Data od = (Data)other;
|
||||
return
|
||||
languageAliases.equals(od.languageAliases) &&
|
||||
|
@ -105,6 +105,11 @@ public final class XLikelySubtags {
|
|||
Arrays.equals(trie, od.trie) &&
|
||||
Arrays.equals(lsrs, od.lsrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() { // unused; silence ErrorProne
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// VisibleForTesting
|
||||
|
|
|
@ -15,7 +15,6 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.ibm.icu.impl.locale.LSR;
|
||||
import com.ibm.icu.impl.locale.LocaleDistance;
|
||||
|
@ -522,19 +521,19 @@ public final class LocaleMatcher {
|
|||
public String toString() {
|
||||
StringBuilder s = new StringBuilder().append("{LocaleMatcher.Builder");
|
||||
if (supportedLocales != null && !supportedLocales.isEmpty()) {
|
||||
s.append(" supported={").append(supportedLocales.toString()).append('}');
|
||||
s.append(" supported={").append(supportedLocales).append('}');
|
||||
}
|
||||
if (defaultLocale != null) {
|
||||
s.append(" default=").append(defaultLocale.toString());
|
||||
s.append(" default=").append(defaultLocale);
|
||||
}
|
||||
if (favor != null) {
|
||||
s.append(" distance=").append(favor.toString());
|
||||
s.append(" distance=").append(favor);
|
||||
}
|
||||
if (thresholdDistance >= 0) {
|
||||
s.append(String.format(" threshold=%d", thresholdDistance));
|
||||
}
|
||||
if (demotion != null) {
|
||||
s.append(" demotion=").append(demotion.toString());
|
||||
s.append(" demotion=").append(demotion);
|
||||
}
|
||||
return s.append('}').toString();
|
||||
}
|
||||
|
@ -1018,7 +1017,7 @@ public final class LocaleMatcher {
|
|||
double distance = LocaleDistance.getDistanceDouble(indexAndDistance);
|
||||
if (TRACE_MATCHER) {
|
||||
System.err.printf("LocaleMatcher distance(desired=%s, supported=%s)=%g\n",
|
||||
Objects.toString(desired), Objects.toString(supported), distance);
|
||||
String.valueOf(desired), String.valueOf(supported), distance);
|
||||
}
|
||||
return (100.0 - distance) / 100.0;
|
||||
}
|
||||
|
@ -1050,15 +1049,15 @@ public final class LocaleMatcher {
|
|||
StringBuilder s = new StringBuilder().append("{LocaleMatcher");
|
||||
// Supported languages in the order that we try to match them.
|
||||
if (supportedLSRs.length > 0) {
|
||||
s.append(" supportedLSRs={").append(supportedLSRs[0].toString());
|
||||
s.append(" supportedLSRs={").append(supportedLSRs[0]);
|
||||
for (int i = 1; i < supportedLSRs.length; ++i) {
|
||||
s.append(", ").append(supportedLSRs[i].toString());
|
||||
s.append(", ").append(supportedLSRs[i]);
|
||||
}
|
||||
s.append('}');
|
||||
}
|
||||
s.append(" default=").append(Objects.toString(defaultULocale));
|
||||
s.append(" default=").append(defaultULocale);
|
||||
if (favorSubtag != null) {
|
||||
s.append(" favor=").append(favorSubtag.toString());
|
||||
s.append(" favor=").append(favorSubtag);
|
||||
}
|
||||
if (thresholdDistance >= 0) {
|
||||
s.append(String.format(" threshold=%d", thresholdDistance));
|
||||
|
|
Loading…
Add table
Reference in a new issue