Skip to content

Commit

Permalink
ICU-22696 Avoid unnecessary copies of already NUL terminated strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
roubert committed Aug 13, 2024
1 parent 7220649 commit bae2aa6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion icu4c/source/common/ulocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ U_NAMESPACE_USE
ULocale*
ulocale_openForLocaleID(const char* localeID, int32_t length, UErrorCode* err) {
if (U_FAILURE(*err)) { return nullptr; }
CharString str(length < 0 ? StringPiece(localeID) : StringPiece(localeID, length), *err);
if (length < 0) {
return EXTERNAL(icu::Locale::createFromName(localeID).clone());
}
CharString str(localeID, length, *err); // Make a NUL terminated copy.
if (U_FAILURE(*err)) { return nullptr; }
return EXTERNAL(icu::Locale::createFromName(str.data()).clone());
}
Expand Down

0 comments on commit bae2aa6

Please sign in to comment.