mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 07:39:16 +00:00
ICU-22494 Avoid adding empty or duplicate variants during locale canoncalization.
It change the failure case (see the bug) from 35s to 0.126s on a very fast developement machine.
This commit is contained in:
parent
687feb1eaa
commit
35645abdcb
1 changed files with 15 additions and 3 deletions
|
@ -1067,7 +1067,13 @@ class AliasReplacer {
|
|||
public:
|
||||
AliasReplacer(UErrorCode status) :
|
||||
language(nullptr), script(nullptr), region(nullptr),
|
||||
extensions(nullptr), variants(status),
|
||||
extensions(nullptr),
|
||||
// store value in variants only once
|
||||
variants(nullptr,
|
||||
([](UElement e1, UElement e2) -> UBool {
|
||||
return 0==uprv_strcmp((const char*)e1.pointer,
|
||||
(const char*)e2.pointer);}),
|
||||
status),
|
||||
data(nullptr) {
|
||||
}
|
||||
~AliasReplacer() {
|
||||
|
@ -1653,10 +1659,16 @@ AliasReplacer::replace(const Locale& locale, CharString& out, UErrorCode& status
|
|||
while ((end = uprv_strchr(start, SEP_CHAR)) != nullptr &&
|
||||
U_SUCCESS(status)) {
|
||||
*end = NULL_CHAR; // null terminate inside variantsBuff
|
||||
variants.addElement(start, status);
|
||||
// do not add "" or duplicate data to variants
|
||||
if (*start && !variants.contains(start)) {
|
||||
variants.addElement(start, status);
|
||||
}
|
||||
start = end + 1;
|
||||
}
|
||||
variants.addElement(start, status);
|
||||
// do not add "" or duplicate data to variants
|
||||
if (*start && !variants.contains(start)) {
|
||||
variants.addElement(start, status);
|
||||
}
|
||||
}
|
||||
if (U_FAILURE(status)) { return false; }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue