Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(743)

Side by Side Diff: src/builtins/builtins-string.cc

Issue 2452543003: Don't wrap roots in Handle just to dereference immediately. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins-math.cc ('k') | src/frames.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 end = str->length(); 813 end = str->length();
814 } else { 814 } else {
815 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position, 815 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position,
816 Object::ToInteger(isolate, position)); 816 Object::ToInteger(isolate, position));
817 double index = std::max(position->Number(), 0.0); 817 double index = std::max(position->Number(), 0.0);
818 index = std::min(index, static_cast<double>(str->length())); 818 index = std::min(index, static_cast<double>(str->length()));
819 end = static_cast<uint32_t>(index); 819 end = static_cast<uint32_t>(index);
820 } 820 }
821 821
822 int start = end - search_string->length(); 822 int start = end - search_string->length();
823 if (start < 0) return *isolate->factory()->false_value(); 823 if (start < 0) return isolate->heap()->false_value();
824 824
825 FlatStringReader str_reader(isolate, String::Flatten(str)); 825 FlatStringReader str_reader(isolate, String::Flatten(str));
826 FlatStringReader search_reader(isolate, String::Flatten(search_string)); 826 FlatStringReader search_reader(isolate, String::Flatten(search_string));
827 827
828 for (int i = 0; i < search_string->length(); i++) { 828 for (int i = 0; i < search_string->length(); i++) {
829 if (str_reader.Get(start + i) != search_reader.Get(i)) { 829 if (str_reader.Get(start + i) != search_reader.Get(i)) {
830 return *isolate->factory()->false_value(); 830 return isolate->heap()->false_value();
831 } 831 }
832 } 832 }
833 return *isolate->factory()->true_value(); 833 return isolate->heap()->true_value();
834 } 834 }
835 835
836 // ES6 section 21.1.3.7 836 // ES6 section 21.1.3.7
837 // String.prototype.includes ( searchString [ , position ] ) 837 // String.prototype.includes ( searchString [ , position ] )
838 BUILTIN(StringPrototypeIncludes) { 838 BUILTIN(StringPrototypeIncludes) {
839 HandleScope handle_scope(isolate); 839 HandleScope handle_scope(isolate);
840 TO_THIS_STRING(str, "String.prototype.includes"); 840 TO_THIS_STRING(str, "String.prototype.includes");
841 841
842 // Check if the search string is a regExp and fail if it is. 842 // Check if the search string is a regExp and fail if it is.
843 Handle<Object> search = args.atOrUndefined(isolate, 1); 843 Handle<Object> search = args.atOrUndefined(isolate, 1);
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 start = 0; 1232 start = 0;
1233 } else { 1233 } else {
1234 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position, 1234 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position,
1235 Object::ToInteger(isolate, position)); 1235 Object::ToInteger(isolate, position));
1236 double index = std::max(position->Number(), 0.0); 1236 double index = std::max(position->Number(), 0.0);
1237 index = std::min(index, static_cast<double>(str->length())); 1237 index = std::min(index, static_cast<double>(str->length()));
1238 start = static_cast<uint32_t>(index); 1238 start = static_cast<uint32_t>(index);
1239 } 1239 }
1240 1240
1241 if (start + search_string->length() > str->length()) { 1241 if (start + search_string->length() > str->length()) {
1242 return *isolate->factory()->false_value(); 1242 return isolate->heap()->false_value();
1243 } 1243 }
1244 1244
1245 FlatStringReader str_reader(isolate, String::Flatten(str)); 1245 FlatStringReader str_reader(isolate, String::Flatten(str));
1246 FlatStringReader search_reader(isolate, String::Flatten(search_string)); 1246 FlatStringReader search_reader(isolate, String::Flatten(search_string));
1247 1247
1248 for (int i = 0; i < search_string->length(); i++) { 1248 for (int i = 0; i < search_string->length(); i++) {
1249 if (str_reader.Get(start + i) != search_reader.Get(i)) { 1249 if (str_reader.Get(start + i) != search_reader.Get(i)) {
1250 return *isolate->factory()->false_value(); 1250 return isolate->heap()->false_value();
1251 } 1251 }
1252 } 1252 }
1253 return *isolate->factory()->true_value(); 1253 return isolate->heap()->true_value();
1254 } 1254 }
1255 1255
1256 // ES6 section 21.1.3.25 String.prototype.toString () 1256 // ES6 section 21.1.3.25 String.prototype.toString ()
1257 void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) { 1257 void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) {
1258 typedef compiler::Node Node; 1258 typedef compiler::Node Node;
1259 1259
1260 Node* receiver = assembler->Parameter(0); 1260 Node* receiver = assembler->Parameter(0);
1261 Node* context = assembler->Parameter(3); 1261 Node* context = assembler->Parameter(3);
1262 1262
1263 Node* result = assembler->ToThisValue( 1263 Node* result = assembler->ToThisValue(
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 Runtime::kThrowIncompatibleMethodReceiver, context, 1491 Runtime::kThrowIncompatibleMethodReceiver, context,
1492 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked( 1492 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked(
1493 "String Iterator.prototype.next", TENURED)), 1493 "String Iterator.prototype.next", TENURED)),
1494 iterator); 1494 iterator);
1495 assembler->Return(result); // Never reached. 1495 assembler->Return(result); // Never reached.
1496 } 1496 }
1497 } 1497 }
1498 1498
1499 } // namespace internal 1499 } // namespace internal
1500 } // namespace v8 1500 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins-math.cc ('k') | src/frames.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698