Commit ee50747e authored by petermarshall's avatar petermarshall Committed by Commit bot

[builtins] Improve StringPrototypeEndsWith performance by adding a fastpath.

If the strings are both onebyte strings, then use memcmp on the underlying data stores.

BUG=chromium:657747

Review-Url: https://codereview.chromium.org/2502323002
Cr-Commit-Position: refs/heads/master@{#41033}
parent 31a8ec77
......@@ -770,8 +770,24 @@ BUILTIN(StringPrototypeEndsWith) {
int start = end - search_string->length();
if (start < 0) return isolate->heap()->false_value();
FlatStringReader str_reader(isolate, String::Flatten(str));
FlatStringReader search_reader(isolate, String::Flatten(search_string));
str = String::Flatten(str);
search_string = String::Flatten(search_string);
DisallowHeapAllocation no_gc; // ensure vectors stay valid
String::FlatContent str_content = str->GetFlatContent();
String::FlatContent search_content = search_string->GetFlatContent();
if (str_content.IsOneByte() && search_content.IsOneByte()) {
Vector<const uint8_t> str_vector = str_content.ToOneByteVector();
Vector<const uint8_t> search_vector = search_content.ToOneByteVector();
return isolate->heap()->ToBoolean(memcmp(str_vector.start() + start,
search_vector.start(),
search_string->length()) == 0);
}
FlatStringReader str_reader(isolate, str);
FlatStringReader search_reader(isolate, search_string);
for (int i = 0; i < search_string->length(); i++) {
if (str_reader.Get(start + i) != search_reader.Get(i)) {
......
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