Index: src/builtins/builtins-string.cc |
diff --git a/src/builtins/builtins-string.cc b/src/builtins/builtins-string.cc |
index 4ccccbc85970cb89ab3977d9ac9c7791d918cdc6..a5439017c9fb76d9aa6e5ce50581b12b5b813806 100644 |
--- a/src/builtins/builtins-string.cc |
+++ b/src/builtins/builtins-string.cc |
@@ -758,8 +758,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)) { |