Commit 779e9e06 authored by Balaram Makam's avatar Balaram Makam Committed by Commit Bot

[intl] Remove redundant flattening of strings.

Patch from Chukwuchebem Orakwue <c.orakwue@samsung.com>

Change-Id: Ic5b302f4965b0f032839ef06e1221f56c37f76a1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1582055Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61341}
parent 6a932d41
......@@ -193,15 +193,13 @@ const uint8_t* Intl::ToLatin1LowerTable() { return &kToLower[0]; }
icu::UnicodeString Intl::ToICUUnicodeString(Isolate* isolate,
Handle<String> string) {
string = String::Flatten(isolate, string);
{
DisallowHeapAllocation no_gc;
std::unique_ptr<uc16[]> sap;
return icu::UnicodeString(
GetUCharBufferFromFlat(string->GetFlatContent(no_gc), &sap,
string->length()),
string->length());
}
DCHECK(string->IsFlat());
DisallowHeapAllocation no_gc;
std::unique_ptr<uc16[]> sap;
return icu::UnicodeString(
GetUCharBufferFromFlat(string->GetFlatContent(no_gc), &sap,
string->length()),
string->length());
}
namespace {
......@@ -1671,6 +1669,7 @@ Intl::ResolvedLocale Intl::ResolveLocale(
Managed<icu::UnicodeString> Intl::SetTextToBreakIterator(
Isolate* isolate, Handle<String> text, icu::BreakIterator* break_iterator) {
text = String::Flatten(isolate, text);
icu::UnicodeString* u_text =
(icu::UnicodeString*)(Intl::ToICUUnicodeString(isolate, text).clone());
......
......@@ -286,8 +286,9 @@ Maybe<std::vector<icu::UnicodeString>> ToUnicodeStringArray(
factory->NewNumber(i), factory->String_string()),
Nothing<std::vector<icu::UnicodeString>>());
}
result.push_back(
Intl::ToICUUnicodeString(isolate, Handle<String>::cast(item)));
Handle<String> item_str = Handle<String>::cast(item);
if (!item_str->IsFlat()) item_str = String::Flatten(isolate, item_str);
result.push_back(Intl::ToICUUnicodeString(isolate, item_str));
}
DCHECK(!array->HasDictionaryElements());
return Just(result);
......
......@@ -41,6 +41,10 @@ function testFormatter(listFormat) {
assertThrows(() => listFormat.format([null, 'world']), TypeError);
assertThrows(() => listFormat.format(['hello', null]), TypeError);
assertThrows(() => listFormat.format([null]), TypeError);
// Test that Cons strings are handled correctly.
let arr = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"];
assertListFormat(listFormat, [arr + "n"]);
}
testFormatter(new Intl.ListFormat());
testFormatter(new Intl.ListFormat(["en"]));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment