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

Side by Side Diff: src/runtime.cc

Issue 50073005: 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 4397 matching lines...) Expand 10 before | Expand all | Expand 10 after
4408 uint16_t char1 = stream1.GetNext(); 4408 uint16_t char1 = stream1.GetNext();
4409 uint16_t char2 = stream2.GetNext(); 4409 uint16_t char2 = stream2.GetNext();
4410 if (char1 != char2) return Smi::FromInt(char1 - char2); 4410 if (char1 != char2) return Smi::FromInt(char1 - char2);
4411 } 4411 }
4412 4412
4413 return Smi::FromInt(str1_length - str2_length); 4413 return Smi::FromInt(str1_length - str2_length);
4414 } 4414 }
4415 4415
4416 4416
4417 RUNTIME_FUNCTION(MaybeObject*, Runtime_SubString) { 4417 RUNTIME_FUNCTION(MaybeObject*, Runtime_SubString) {
4418 SealHandleScope shs(isolate); 4418 HandleScope scope(isolate);
4419 ASSERT(args.length() == 3); 4419 ASSERT(args.length() == 3);
4420 4420
4421 CONVERT_ARG_CHECKED(String, value, 0); 4421 CONVERT_ARG_HANDLE_CHECKED(String, string, 0);
4422 int start, end; 4422 int start, end;
4423 // We have a fast integer-only case here to avoid a conversion to double in 4423 // We have a fast integer-only case here to avoid a conversion to double in
4424 // the common case where from and to are Smis. 4424 // the common case where from and to are Smis.
4425 if (args[1]->IsSmi() && args[2]->IsSmi()) { 4425 if (args[1]->IsSmi() && args[2]->IsSmi()) {
4426 CONVERT_SMI_ARG_CHECKED(from_number, 1); 4426 CONVERT_SMI_ARG_CHECKED(from_number, 1);
4427 CONVERT_SMI_ARG_CHECKED(to_number, 2); 4427 CONVERT_SMI_ARG_CHECKED(to_number, 2);
4428 start = from_number; 4428 start = from_number;
4429 end = to_number; 4429 end = to_number;
4430 } else { 4430 } else {
4431 CONVERT_DOUBLE_ARG_CHECKED(from_number, 1); 4431 CONVERT_DOUBLE_ARG_CHECKED(from_number, 1);
4432 CONVERT_DOUBLE_ARG_CHECKED(to_number, 2); 4432 CONVERT_DOUBLE_ARG_CHECKED(to_number, 2);
4433 start = FastD2IChecked(from_number); 4433 start = FastD2IChecked(from_number);
4434 end = FastD2IChecked(to_number); 4434 end = FastD2IChecked(to_number);
4435 } 4435 }
4436 RUNTIME_ASSERT(end >= start); 4436 RUNTIME_ASSERT(end >= start);
4437 RUNTIME_ASSERT(start >= 0); 4437 RUNTIME_ASSERT(start >= 0);
4438 RUNTIME_ASSERT(end <= value->length()); 4438 RUNTIME_ASSERT(end <= string->length());
4439 isolate->counters()->sub_string_runtime()->Increment(); 4439 isolate->counters()->sub_string_runtime()->Increment();
4440 if (end - start == 1) { 4440
4441 return isolate->heap()->LookupSingleCharacterStringFromCode( 4441 return *isolate->factory()->NewSubString(string, start, end);
4442 value->Get(start));
4443 }
4444 return value->SubString(start, end);
4445 } 4442 }
4446 4443
4447 4444
4448 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) { 4445 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) {
4449 HandleScope handles(isolate); 4446 HandleScope handles(isolate);
4450 ASSERT_EQ(3, args.length()); 4447 ASSERT_EQ(3, args.length());
4451 4448
4452 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); 4449 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
4453 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); 4450 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1);
4454 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2); 4451 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2);
(...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after
6521 args, isolate, isolate->runtime_state()->to_upper_mapping()); 6518 args, isolate, isolate->runtime_state()->to_upper_mapping());
6522 } 6519 }
6523 6520
6524 6521
6525 static inline bool IsTrimWhiteSpace(unibrow::uchar c) { 6522 static inline bool IsTrimWhiteSpace(unibrow::uchar c) {
6526 return unibrow::WhiteSpace::Is(c) || c == 0x200b || c == 0xfeff; 6523 return unibrow::WhiteSpace::Is(c) || c == 0x200b || c == 0xfeff;
6527 } 6524 }
6528 6525
6529 6526
6530 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringTrim) { 6527 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringTrim) {
6531 SealHandleScope shs(isolate); 6528 HandleScope scope(isolate);
6532 ASSERT(args.length() == 3); 6529 ASSERT(args.length() == 3);
6533 6530
6534 CONVERT_ARG_CHECKED(String, s, 0); 6531 CONVERT_ARG_HANDLE_CHECKED(String, string, 0);
6535 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1); 6532 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1);
6536 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2); 6533 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2);
6537 6534
6538 s->TryFlatten(); 6535 string = FlattenGetString(string);
6539 int length = s->length(); 6536 int length = string->length();
6540 6537
6541 int left = 0; 6538 int left = 0;
6542 if (trimLeft) { 6539 if (trimLeft) {
6543 while (left < length && IsTrimWhiteSpace(s->Get(left))) { 6540 while (left < length && IsTrimWhiteSpace(string->Get(left))) {
6544 left++; 6541 left++;
6545 } 6542 }
6546 } 6543 }
6547 6544
6548 int right = length; 6545 int right = length;
6549 if (trimRight) { 6546 if (trimRight) {
6550 while (right > left && IsTrimWhiteSpace(s->Get(right - 1))) { 6547 while (right > left && IsTrimWhiteSpace(string->Get(right - 1))) {
6551 right--; 6548 right--;
6552 } 6549 }
6553 } 6550 }
6554 return s->SubString(left, right); 6551
6552 return *isolate->factory()->NewSubString(string, left, right);
6555 } 6553 }
6556 6554
6557 6555
6558 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) { 6556 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) {
6559 HandleScope handle_scope(isolate); 6557 HandleScope handle_scope(isolate);
6560 ASSERT(args.length() == 3); 6558 ASSERT(args.length() == 3);
6561 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); 6559 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
6562 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); 6560 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1);
6563 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); 6561 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]);
6564 6562
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
6947 SealHandleScope shs(isolate); 6945 SealHandleScope shs(isolate);
6948 ASSERT(args.length() == 2); 6946 ASSERT(args.length() == 2);
6949 6947
6950 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); 6948 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]);
6951 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); 6949 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]);
6952 return isolate->heap()->NumberFromInt32(x * y); 6950 return isolate->heap()->NumberFromInt32(x * y);
6953 } 6951 }
6954 6952
6955 6953
6956 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringAdd) { 6954 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringAdd) {
6957 SealHandleScope shs(isolate); 6955 HandleScope scope(isolate);
6958 ASSERT(args.length() == 2); 6956 ASSERT(args.length() == 2);
6959 CONVERT_ARG_CHECKED(String, str1, 0); 6957 CONVERT_ARG_HANDLE_CHECKED(String, str1, 0);
6960 CONVERT_ARG_CHECKED(String, str2, 1); 6958 CONVERT_ARG_HANDLE_CHECKED(String, str2, 1);
6961 isolate->counters()->string_add_runtime()->Increment(); 6959 isolate->counters()->string_add_runtime()->Increment();
6962 return isolate->heap()->AllocateConsString(str1, str2); 6960 return *isolate->factory()->NewConsString(str1, str2);
6963 } 6961 }
6964 6962
6965 6963
6966 template <typename sinkchar> 6964 template <typename sinkchar>
6967 static inline void StringBuilderConcatHelper(String* special, 6965 static inline void StringBuilderConcatHelper(String* special,
6968 sinkchar* sink, 6966 sinkchar* sink,
6969 FixedArray* fixed_array, 6967 FixedArray* fixed_array,
6970 int array_length) { 6968 int array_length) {
6971 int position = 0; 6969 int position = 0;
6972 for (int i = 0; i < array_length; i++) { 6970 for (int i = 0; i < array_length; i++) {
(...skipping 7893 matching lines...) Expand 10 before | Expand all | Expand 10 after
14866 // Handle last resort GC and make sure to allow future allocations 14864 // Handle last resort GC and make sure to allow future allocations
14867 // to grow the heap without causing GCs (if possible). 14865 // to grow the heap without causing GCs (if possible).
14868 isolate->counters()->gc_last_resort_from_js()->Increment(); 14866 isolate->counters()->gc_last_resort_from_js()->Increment();
14869 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14867 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14870 "Runtime::PerformGC"); 14868 "Runtime::PerformGC");
14871 } 14869 }
14872 } 14870 }
14873 14871
14874 14872
14875 } } // namespace v8::internal 14873 } } // 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