OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/builtins/builtins.h" | 5 #include "src/builtins/builtins.h" |
6 #include "src/builtins/builtins-utils.h" | 6 #include "src/builtins/builtins-utils.h" |
7 | 7 |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/regexp/regexp-utils.h" | 9 #include "src/regexp/regexp-utils.h" |
10 | 10 |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position, | 751 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position, |
752 Object::ToInteger(isolate, position)); | 752 Object::ToInteger(isolate, position)); |
753 double index = std::max(position->Number(), 0.0); | 753 double index = std::max(position->Number(), 0.0); |
754 index = std::min(index, static_cast<double>(str->length())); | 754 index = std::min(index, static_cast<double>(str->length())); |
755 end = static_cast<uint32_t>(index); | 755 end = static_cast<uint32_t>(index); |
756 } | 756 } |
757 | 757 |
758 int start = end - search_string->length(); | 758 int start = end - search_string->length(); |
759 if (start < 0) return isolate->heap()->false_value(); | 759 if (start < 0) return isolate->heap()->false_value(); |
760 | 760 |
761 FlatStringReader str_reader(isolate, String::Flatten(str)); | 761 str = String::Flatten(str); |
762 FlatStringReader search_reader(isolate, String::Flatten(search_string)); | 762 search_string = String::Flatten(search_string); |
| 763 |
| 764 DisallowHeapAllocation no_gc; // ensure vectors stay valid |
| 765 String::FlatContent str_content = str->GetFlatContent(); |
| 766 String::FlatContent search_content = search_string->GetFlatContent(); |
| 767 |
| 768 if (str_content.IsOneByte() && search_content.IsOneByte()) { |
| 769 Vector<const uint8_t> str_vector = str_content.ToOneByteVector(); |
| 770 Vector<const uint8_t> search_vector = search_content.ToOneByteVector(); |
| 771 |
| 772 return isolate->heap()->ToBoolean(memcmp(str_vector.start() + start, |
| 773 search_vector.start(), |
| 774 search_string->length()) == 0); |
| 775 } |
| 776 |
| 777 FlatStringReader str_reader(isolate, str); |
| 778 FlatStringReader search_reader(isolate, search_string); |
763 | 779 |
764 for (int i = 0; i < search_string->length(); i++) { | 780 for (int i = 0; i < search_string->length(); i++) { |
765 if (str_reader.Get(start + i) != search_reader.Get(i)) { | 781 if (str_reader.Get(start + i) != search_reader.Get(i)) { |
766 return isolate->heap()->false_value(); | 782 return isolate->heap()->false_value(); |
767 } | 783 } |
768 } | 784 } |
769 return isolate->heap()->true_value(); | 785 return isolate->heap()->true_value(); |
770 } | 786 } |
771 | 787 |
772 // ES6 section 21.1.3.7 | 788 // ES6 section 21.1.3.7 |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 Runtime::kThrowIncompatibleMethodReceiver, context, | 1443 Runtime::kThrowIncompatibleMethodReceiver, context, |
1428 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked( | 1444 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked( |
1429 "String Iterator.prototype.next", TENURED)), | 1445 "String Iterator.prototype.next", TENURED)), |
1430 iterator); | 1446 iterator); |
1431 assembler->Return(result); // Never reached. | 1447 assembler->Return(result); // Never reached. |
1432 } | 1448 } |
1433 } | 1449 } |
1434 | 1450 |
1435 } // namespace internal | 1451 } // namespace internal |
1436 } // namespace v8 | 1452 } // namespace v8 |
OLD | NEW |