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

Side by Side Diff: src/runtime.cc

Issue 114943004: Reland "Handlify concat string and substring." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix test case. Created 7 years 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/cctest/test-api.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 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 4431 matching lines...) Expand 10 before | Expand all | Expand 10 after
4442 uint16_t char1 = stream1.GetNext(); 4442 uint16_t char1 = stream1.GetNext();
4443 uint16_t char2 = stream2.GetNext(); 4443 uint16_t char2 = stream2.GetNext();
4444 if (char1 != char2) return Smi::FromInt(char1 - char2); 4444 if (char1 != char2) return Smi::FromInt(char1 - char2);
4445 } 4445 }
4446 4446
4447 return Smi::FromInt(str1_length - str2_length); 4447 return Smi::FromInt(str1_length - str2_length);
4448 } 4448 }
4449 4449
4450 4450
4451 RUNTIME_FUNCTION(MaybeObject*, Runtime_SubString) { 4451 RUNTIME_FUNCTION(MaybeObject*, Runtime_SubString) {
4452 SealHandleScope shs(isolate); 4452 HandleScope scope(isolate);
4453 ASSERT(args.length() == 3); 4453 ASSERT(args.length() == 3);
4454 4454
4455 CONVERT_ARG_CHECKED(String, value, 0); 4455 CONVERT_ARG_HANDLE_CHECKED(String, string, 0);
4456 int start, end; 4456 int start, end;
4457 // We have a fast integer-only case here to avoid a conversion to double in 4457 // We have a fast integer-only case here to avoid a conversion to double in
4458 // the common case where from and to are Smis. 4458 // the common case where from and to are Smis.
4459 if (args[1]->IsSmi() && args[2]->IsSmi()) { 4459 if (args[1]->IsSmi() && args[2]->IsSmi()) {
4460 CONVERT_SMI_ARG_CHECKED(from_number, 1); 4460 CONVERT_SMI_ARG_CHECKED(from_number, 1);
4461 CONVERT_SMI_ARG_CHECKED(to_number, 2); 4461 CONVERT_SMI_ARG_CHECKED(to_number, 2);
4462 start = from_number; 4462 start = from_number;
4463 end = to_number; 4463 end = to_number;
4464 } else { 4464 } else {
4465 CONVERT_DOUBLE_ARG_CHECKED(from_number, 1); 4465 CONVERT_DOUBLE_ARG_CHECKED(from_number, 1);
4466 CONVERT_DOUBLE_ARG_CHECKED(to_number, 2); 4466 CONVERT_DOUBLE_ARG_CHECKED(to_number, 2);
4467 start = FastD2IChecked(from_number); 4467 start = FastD2IChecked(from_number);
4468 end = FastD2IChecked(to_number); 4468 end = FastD2IChecked(to_number);
4469 } 4469 }
4470 RUNTIME_ASSERT(end >= start); 4470 RUNTIME_ASSERT(end >= start);
4471 RUNTIME_ASSERT(start >= 0); 4471 RUNTIME_ASSERT(start >= 0);
4472 RUNTIME_ASSERT(end <= value->length()); 4472 RUNTIME_ASSERT(end <= string->length());
4473 isolate->counters()->sub_string_runtime()->Increment(); 4473 isolate->counters()->sub_string_runtime()->Increment();
4474 return value->SubString(start, end); 4474
4475 return *isolate->factory()->NewSubString(string, start, end);
4475 } 4476 }
4476 4477
4477 4478
4478 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) { 4479 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) {
4479 HandleScope handles(isolate); 4480 HandleScope handles(isolate);
4480 ASSERT_EQ(3, args.length()); 4481 ASSERT_EQ(3, args.length());
4481 4482
4482 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); 4483 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
4483 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); 4484 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1);
4484 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2); 4485 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2);
(...skipping 2060 matching lines...) Expand 10 before | Expand all | Expand 10 after
6545 args, isolate, isolate->runtime_state()->to_upper_mapping()); 6546 args, isolate, isolate->runtime_state()->to_upper_mapping());
6546 } 6547 }
6547 6548
6548 6549
6549 static inline bool IsTrimWhiteSpace(unibrow::uchar c) { 6550 static inline bool IsTrimWhiteSpace(unibrow::uchar c) {
6550 return unibrow::WhiteSpace::Is(c) || c == 0x200b || c == 0xfeff; 6551 return unibrow::WhiteSpace::Is(c) || c == 0x200b || c == 0xfeff;
6551 } 6552 }
6552 6553
6553 6554
6554 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringTrim) { 6555 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringTrim) {
6555 SealHandleScope shs(isolate); 6556 HandleScope scope(isolate);
6556 ASSERT(args.length() == 3); 6557 ASSERT(args.length() == 3);
6557 6558
6558 CONVERT_ARG_CHECKED(String, s, 0); 6559 CONVERT_ARG_HANDLE_CHECKED(String, string, 0);
6559 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1); 6560 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1);
6560 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2); 6561 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2);
6561 6562
6562 s->TryFlatten(); 6563 string = FlattenGetString(string);
6563 int length = s->length(); 6564 int length = string->length();
6564 6565
6565 int left = 0; 6566 int left = 0;
6566 if (trimLeft) { 6567 if (trimLeft) {
6567 while (left < length && IsTrimWhiteSpace(s->Get(left))) { 6568 while (left < length && IsTrimWhiteSpace(string->Get(left))) {
6568 left++; 6569 left++;
6569 } 6570 }
6570 } 6571 }
6571 6572
6572 int right = length; 6573 int right = length;
6573 if (trimRight) { 6574 if (trimRight) {
6574 while (right > left && IsTrimWhiteSpace(s->Get(right - 1))) { 6575 while (right > left && IsTrimWhiteSpace(string->Get(right - 1))) {
6575 right--; 6576 right--;
6576 } 6577 }
6577 } 6578 }
6578 return s->SubString(left, right); 6579
6580 return *isolate->factory()->NewSubString(string, left, right);
6579 } 6581 }
6580 6582
6581 6583
6582 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) { 6584 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) {
6583 HandleScope handle_scope(isolate); 6585 HandleScope handle_scope(isolate);
6584 ASSERT(args.length() == 3); 6586 ASSERT(args.length() == 3);
6585 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); 6587 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
6586 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); 6588 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1);
6587 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); 6589 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]);
6588 6590
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
6971 SealHandleScope shs(isolate); 6973 SealHandleScope shs(isolate);
6972 ASSERT(args.length() == 2); 6974 ASSERT(args.length() == 2);
6973 6975
6974 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); 6976 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]);
6975 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); 6977 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]);
6976 return isolate->heap()->NumberFromInt32(x * y); 6978 return isolate->heap()->NumberFromInt32(x * y);
6977 } 6979 }
6978 6980
6979 6981
6980 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringAdd) { 6982 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringAdd) {
6981 SealHandleScope shs(isolate); 6983 HandleScope scope(isolate);
6982 ASSERT(args.length() == 2); 6984 ASSERT(args.length() == 2);
6983 CONVERT_ARG_CHECKED(String, str1, 0); 6985 CONVERT_ARG_HANDLE_CHECKED(String, str1, 0);
6984 CONVERT_ARG_CHECKED(String, str2, 1); 6986 CONVERT_ARG_HANDLE_CHECKED(String, str2, 1);
6985 isolate->counters()->string_add_runtime()->Increment(); 6987 isolate->counters()->string_add_runtime()->Increment();
6986 return isolate->heap()->AllocateConsString(str1, str2); 6988 return *isolate->factory()->NewConsString(str1, str2);
6987 } 6989 }
6988 6990
6989 6991
6990 template <typename sinkchar> 6992 template <typename sinkchar>
6991 static inline void StringBuilderConcatHelper(String* special, 6993 static inline void StringBuilderConcatHelper(String* special,
6992 sinkchar* sink, 6994 sinkchar* sink,
6993 FixedArray* fixed_array, 6995 FixedArray* fixed_array,
6994 int array_length) { 6996 int array_length) {
6995 int position = 0; 6997 int position = 0;
6996 for (int i = 0; i < array_length; i++) { 6998 for (int i = 0; i < array_length; i++) {
(...skipping 7906 matching lines...) Expand 10 before | Expand all | Expand 10 after
14903 // Handle last resort GC and make sure to allow future allocations 14905 // Handle last resort GC and make sure to allow future allocations
14904 // to grow the heap without causing GCs (if possible). 14906 // to grow the heap without causing GCs (if possible).
14905 isolate->counters()->gc_last_resort_from_js()->Increment(); 14907 isolate->counters()->gc_last_resort_from_js()->Increment();
14906 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14908 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14907 "Runtime::PerformGC"); 14909 "Runtime::PerformGC");
14908 } 14910 }
14909 } 14911 }
14910 14912
14911 14913
14912 } } // namespace v8::internal 14914 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698