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

Side by Side Diff: src/runtime.cc

Issue 59973004: Revert "Handlify concat string and substring." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/objects.cc ('k') | test/mjsunit/string-slices.js » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 4369 matching lines...) Expand 10 before | Expand all | Expand 10 after
4380 uint16_t char1 = stream1.GetNext(); 4380 uint16_t char1 = stream1.GetNext();
4381 uint16_t char2 = stream2.GetNext(); 4381 uint16_t char2 = stream2.GetNext();
4382 if (char1 != char2) return Smi::FromInt(char1 - char2); 4382 if (char1 != char2) return Smi::FromInt(char1 - char2);
4383 } 4383 }
4384 4384
4385 return Smi::FromInt(str1_length - str2_length); 4385 return Smi::FromInt(str1_length - str2_length);
4386 } 4386 }
4387 4387
4388 4388
4389 RUNTIME_FUNCTION(MaybeObject*, Runtime_SubString) { 4389 RUNTIME_FUNCTION(MaybeObject*, Runtime_SubString) {
4390 HandleScope scope(isolate); 4390 SealHandleScope shs(isolate);
4391 ASSERT(args.length() == 3); 4391 ASSERT(args.length() == 3);
4392 4392
4393 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); 4393 CONVERT_ARG_CHECKED(String, value, 0);
4394 int start, end; 4394 int start, end;
4395 // We have a fast integer-only case here to avoid a conversion to double in 4395 // We have a fast integer-only case here to avoid a conversion to double in
4396 // the common case where from and to are Smis. 4396 // the common case where from and to are Smis.
4397 if (args[1]->IsSmi() && args[2]->IsSmi()) { 4397 if (args[1]->IsSmi() && args[2]->IsSmi()) {
4398 CONVERT_SMI_ARG_CHECKED(from_number, 1); 4398 CONVERT_SMI_ARG_CHECKED(from_number, 1);
4399 CONVERT_SMI_ARG_CHECKED(to_number, 2); 4399 CONVERT_SMI_ARG_CHECKED(to_number, 2);
4400 start = from_number; 4400 start = from_number;
4401 end = to_number; 4401 end = to_number;
4402 } else { 4402 } else {
4403 CONVERT_DOUBLE_ARG_CHECKED(from_number, 1); 4403 CONVERT_DOUBLE_ARG_CHECKED(from_number, 1);
4404 CONVERT_DOUBLE_ARG_CHECKED(to_number, 2); 4404 CONVERT_DOUBLE_ARG_CHECKED(to_number, 2);
4405 start = FastD2IChecked(from_number); 4405 start = FastD2IChecked(from_number);
4406 end = FastD2IChecked(to_number); 4406 end = FastD2IChecked(to_number);
4407 } 4407 }
4408 RUNTIME_ASSERT(end >= start); 4408 RUNTIME_ASSERT(end >= start);
4409 RUNTIME_ASSERT(start >= 0); 4409 RUNTIME_ASSERT(start >= 0);
4410 RUNTIME_ASSERT(end <= string->length()); 4410 RUNTIME_ASSERT(end <= value->length());
4411 isolate->counters()->sub_string_runtime()->Increment(); 4411 isolate->counters()->sub_string_runtime()->Increment();
4412 4412 if (end - start == 1) {
4413 return *isolate->factory()->NewSubString(string, start, end); 4413 return isolate->heap()->LookupSingleCharacterStringFromCode(
4414 value->Get(start));
4415 }
4416 return value->SubString(start, end);
4414 } 4417 }
4415 4418
4416 4419
4417 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) { 4420 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) {
4418 HandleScope handles(isolate); 4421 HandleScope handles(isolate);
4419 ASSERT_EQ(3, args.length()); 4422 ASSERT_EQ(3, args.length());
4420 4423
4421 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); 4424 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
4422 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); 4425 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1);
4423 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2); 4426 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2);
(...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after
6490 args, isolate, isolate->runtime_state()->to_upper_mapping()); 6493 args, isolate, isolate->runtime_state()->to_upper_mapping());
6491 } 6494 }
6492 6495
6493 6496
6494 static inline bool IsTrimWhiteSpace(unibrow::uchar c) { 6497 static inline bool IsTrimWhiteSpace(unibrow::uchar c) {
6495 return unibrow::WhiteSpace::Is(c) || c == 0x200b || c == 0xfeff; 6498 return unibrow::WhiteSpace::Is(c) || c == 0x200b || c == 0xfeff;
6496 } 6499 }
6497 6500
6498 6501
6499 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringTrim) { 6502 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringTrim) {
6500 HandleScope scope(isolate); 6503 SealHandleScope shs(isolate);
6501 ASSERT(args.length() == 3); 6504 ASSERT(args.length() == 3);
6502 6505
6503 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); 6506 CONVERT_ARG_CHECKED(String, s, 0);
6504 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1); 6507 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1);
6505 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2); 6508 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2);
6506 6509
6507 string = FlattenGetString(string); 6510 s->TryFlatten();
6508 int length = string->length(); 6511 int length = s->length();
6509 6512
6510 int left = 0; 6513 int left = 0;
6511 if (trimLeft) { 6514 if (trimLeft) {
6512 while (left < length && IsTrimWhiteSpace(string->Get(left))) { 6515 while (left < length && IsTrimWhiteSpace(s->Get(left))) {
6513 left++; 6516 left++;
6514 } 6517 }
6515 } 6518 }
6516 6519
6517 int right = length; 6520 int right = length;
6518 if (trimRight) { 6521 if (trimRight) {
6519 while (right > left && IsTrimWhiteSpace(string->Get(right - 1))) { 6522 while (right > left && IsTrimWhiteSpace(s->Get(right - 1))) {
6520 right--; 6523 right--;
6521 } 6524 }
6522 } 6525 }
6523 6526 return s->SubString(left, right);
6524 return *isolate->factory()->NewSubString(string, left, right);
6525 } 6527 }
6526 6528
6527 6529
6528 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) { 6530 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) {
6529 HandleScope handle_scope(isolate); 6531 HandleScope handle_scope(isolate);
6530 ASSERT(args.length() == 3); 6532 ASSERT(args.length() == 3);
6531 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); 6533 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
6532 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); 6534 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1);
6533 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); 6535 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]);
6534 6536
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
6917 SealHandleScope shs(isolate); 6919 SealHandleScope shs(isolate);
6918 ASSERT(args.length() == 2); 6920 ASSERT(args.length() == 2);
6919 6921
6920 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); 6922 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]);
6921 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); 6923 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]);
6922 return isolate->heap()->NumberFromInt32(x * y); 6924 return isolate->heap()->NumberFromInt32(x * y);
6923 } 6925 }
6924 6926
6925 6927
6926 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringAdd) { 6928 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringAdd) {
6927 HandleScope scope(isolate); 6929 SealHandleScope shs(isolate);
6928 ASSERT(args.length() == 2); 6930 ASSERT(args.length() == 2);
6929 CONVERT_ARG_HANDLE_CHECKED(String, str1, 0); 6931 CONVERT_ARG_CHECKED(String, str1, 0);
6930 CONVERT_ARG_HANDLE_CHECKED(String, str2, 1); 6932 CONVERT_ARG_CHECKED(String, str2, 1);
6931 isolate->counters()->string_add_runtime()->Increment(); 6933 isolate->counters()->string_add_runtime()->Increment();
6932 return *isolate->factory()->NewConsString(str1, str2); 6934 return isolate->heap()->AllocateConsString(str1, str2);
6933 } 6935 }
6934 6936
6935 6937
6936 template <typename sinkchar> 6938 template <typename sinkchar>
6937 static inline void StringBuilderConcatHelper(String* special, 6939 static inline void StringBuilderConcatHelper(String* special,
6938 sinkchar* sink, 6940 sinkchar* sink,
6939 FixedArray* fixed_array, 6941 FixedArray* fixed_array,
6940 int array_length) { 6942 int array_length) {
6941 int position = 0; 6943 int position = 0;
6942 for (int i = 0; i < array_length; i++) { 6944 for (int i = 0; i < array_length; i++) {
(...skipping 7893 matching lines...) Expand 10 before | Expand all | Expand 10 after
14836 // Handle last resort GC and make sure to allow future allocations 14838 // Handle last resort GC and make sure to allow future allocations
14837 // to grow the heap without causing GCs (if possible). 14839 // to grow the heap without causing GCs (if possible).
14838 isolate->counters()->gc_last_resort_from_js()->Increment(); 14840 isolate->counters()->gc_last_resort_from_js()->Increment();
14839 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14841 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14840 "Runtime::PerformGC"); 14842 "Runtime::PerformGC");
14841 } 14843 }
14842 } 14844 }
14843 14845
14844 14846
14845 } } // namespace v8::internal 14847 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | test/mjsunit/string-slices.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698