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

Side by Side Diff: src/factory.cc

Issue 258953009: Refactor calls to CALL_HEAP_FUNCTION. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase and addressed comment Created 6 years, 7 months 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/factory.h ('k') | src/isolate.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 "factory.h" 5 #include "factory.h"
6 6
7 #include "conversions.h" 7 #include "conversions.h"
8 #include "isolate-inl.h" 8 #include "isolate-inl.h"
9 #include "macro-assembler.h" 9 #include "macro-assembler.h"
10 10
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 Handle<String> first, 411 Handle<String> first,
412 Handle<String> second) { 412 Handle<String> second) {
413 DisallowHeapAllocation pointer_stays_valid; 413 DisallowHeapAllocation pointer_stays_valid;
414 SinkChar* sink = result->GetChars(); 414 SinkChar* sink = result->GetChars();
415 String::WriteToFlat(*first, sink, 0, first->length()); 415 String::WriteToFlat(*first, sink, 0, first->length());
416 String::WriteToFlat(*second, sink + first->length(), 0, second->length()); 416 String::WriteToFlat(*second, sink + first->length(), 0, second->length());
417 return result; 417 return result;
418 } 418 }
419 419
420 420
421 Handle<ConsString> Factory::NewRawConsString(String::Encoding encoding) {
422 Handle<Map> map = (encoding == String::ONE_BYTE_ENCODING)
423 ? cons_ascii_string_map() : cons_string_map();
424 return New<ConsString>(map, NEW_SPACE);
425 }
426
427
428 MaybeHandle<String> Factory::NewConsString(Handle<String> left, 421 MaybeHandle<String> Factory::NewConsString(Handle<String> left,
429 Handle<String> right) { 422 Handle<String> right) {
430 int left_length = left->length(); 423 int left_length = left->length();
431 if (left_length == 0) return right; 424 if (left_length == 0) return right;
432 int right_length = right->length(); 425 int right_length = right->length();
433 if (right_length == 0) return left; 426 if (right_length == 0) return left;
434 427
435 int length = left_length + right_length; 428 int length = left_length + right_length;
436 429
437 if (length == 2) { 430 if (length == 2) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 return result; 480 return result;
488 } 481 }
489 482
490 return (is_one_byte_data_in_two_byte_string) 483 return (is_one_byte_data_in_two_byte_string)
491 ? ConcatStringContent<uint8_t>( 484 ? ConcatStringContent<uint8_t>(
492 NewRawOneByteString(length).ToHandleChecked(), left, right) 485 NewRawOneByteString(length).ToHandleChecked(), left, right)
493 : ConcatStringContent<uc16>( 486 : ConcatStringContent<uc16>(
494 NewRawTwoByteString(length).ToHandleChecked(), left, right); 487 NewRawTwoByteString(length).ToHandleChecked(), left, right);
495 } 488 }
496 489
497 Handle<ConsString> result = NewRawConsString( 490 Handle<Map> map = (is_one_byte || is_one_byte_data_in_two_byte_string)
498 (is_one_byte || is_one_byte_data_in_two_byte_string) 491 ? cons_ascii_string_map() : cons_string_map();
499 ? String::ONE_BYTE_ENCODING 492 Handle<ConsString> result = New<ConsString>(map, NEW_SPACE);
500 : String::TWO_BYTE_ENCODING);
501 493
502 DisallowHeapAllocation no_gc; 494 DisallowHeapAllocation no_gc;
503 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); 495 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
504 496
505 result->set_hash_field(String::kEmptyHashField); 497 result->set_hash_field(String::kEmptyHashField);
506 result->set_length(length); 498 result->set_length(length);
507 result->set_first(*left, mode); 499 result->set_first(*left, mode);
508 result->set_second(*right, mode); 500 result->set_second(*right, mode);
509 return result; 501 return result;
510 } 502 }
511 503
512 504
513 Handle<String> Factory::NewFlatConcatString(Handle<String> first, 505 Handle<String> Factory::NewFlatConcatString(Handle<String> first,
514 Handle<String> second) { 506 Handle<String> second) {
515 int total_length = first->length() + second->length(); 507 int total_length = first->length() + second->length();
516 if (first->IsOneByteRepresentation() && second->IsOneByteRepresentation()) { 508 if (first->IsOneByteRepresentation() && second->IsOneByteRepresentation()) {
517 return ConcatStringContent<uint8_t>( 509 return ConcatStringContent<uint8_t>(
518 NewRawOneByteString(total_length).ToHandleChecked(), first, second); 510 NewRawOneByteString(total_length).ToHandleChecked(), first, second);
519 } else { 511 } else {
520 return ConcatStringContent<uc16>( 512 return ConcatStringContent<uc16>(
521 NewRawTwoByteString(total_length).ToHandleChecked(), first, second); 513 NewRawTwoByteString(total_length).ToHandleChecked(), first, second);
522 } 514 }
523 } 515 }
524 516
525 517
526 Handle<SlicedString> Factory::NewRawSlicedString(String::Encoding encoding) {
527 Handle<Map> map = (encoding == String::ONE_BYTE_ENCODING)
528 ? sliced_ascii_string_map() : sliced_string_map();
529 return New<SlicedString>(map, NEW_SPACE);
530 }
531
532
533 Handle<String> Factory::NewProperSubString(Handle<String> str, 518 Handle<String> Factory::NewProperSubString(Handle<String> str,
534 int begin, 519 int begin,
535 int end) { 520 int end) {
536 #if VERIFY_HEAP 521 #if VERIFY_HEAP
537 if (FLAG_verify_heap) str->StringVerify(); 522 if (FLAG_verify_heap) str->StringVerify();
538 #endif 523 #endif
539 ASSERT(begin > 0 || end < str->length()); 524 ASSERT(begin > 0 || end < str->length());
540 525
541 str = String::Flatten(str); 526 str = String::Flatten(str);
542 527
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 559
575 int offset = begin; 560 int offset = begin;
576 561
577 if (str->IsSlicedString()) { 562 if (str->IsSlicedString()) {
578 Handle<SlicedString> slice = Handle<SlicedString>::cast(str); 563 Handle<SlicedString> slice = Handle<SlicedString>::cast(str);
579 str = Handle<String>(slice->parent(), isolate()); 564 str = Handle<String>(slice->parent(), isolate());
580 offset += slice->offset(); 565 offset += slice->offset();
581 } 566 }
582 567
583 ASSERT(str->IsSeqString() || str->IsExternalString()); 568 ASSERT(str->IsSeqString() || str->IsExternalString());
584 Handle<SlicedString> slice = NewRawSlicedString( 569 Handle<Map> map = str->IsOneByteRepresentation() ? sliced_ascii_string_map()
585 str->IsOneByteRepresentation() ? String::ONE_BYTE_ENCODING 570 : sliced_string_map();
586 : String::TWO_BYTE_ENCODING); 571 Handle<SlicedString> slice = New<SlicedString>(map, NEW_SPACE);
587 572
588 slice->set_hash_field(String::kEmptyHashField); 573 slice->set_hash_field(String::kEmptyHashField);
589 slice->set_length(length); 574 slice->set_length(length);
590 slice->set_parent(*str); 575 slice->set_parent(*str);
591 slice->set_offset(offset); 576 slice->set_offset(offset);
592 return slice; 577 return slice;
593 } 578 }
594 579
595 580
596 MaybeHandle<String> Factory::NewExternalStringFromAscii( 581 MaybeHandle<String> Factory::NewExternalStringFromAscii(
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 JSObject::SetLocalPropertyIgnoreAttributes(prototype, 931 JSObject::SetLocalPropertyIgnoreAttributes(prototype,
947 constructor_string(), 932 constructor_string(),
948 function, 933 function,
949 DONT_ENUM).Assert(); 934 DONT_ENUM).Assert();
950 } 935 }
951 936
952 return prototype; 937 return prototype;
953 } 938 }
954 939
955 940
941 Handle<JSObject> Factory::CopyJSObject(Handle<JSObject> object) {
942 CALL_HEAP_FUNCTION(isolate(),
943 isolate()->heap()->CopyJSObject(*object, NULL),
944 JSObject);
945 }
946
947
948 Handle<JSObject> Factory::CopyJSObjectWithAllocationSite(
949 Handle<JSObject> object,
950 Handle<AllocationSite> site) {
951 CALL_HEAP_FUNCTION(isolate(),
952 isolate()->heap()->CopyJSObject(
953 *object,
954 site.is_null() ? NULL : *site),
955 JSObject);
956 }
957
958
956 Handle<FixedArray> Factory::CopyFixedArrayWithMap(Handle<FixedArray> array, 959 Handle<FixedArray> Factory::CopyFixedArrayWithMap(Handle<FixedArray> array,
957 Handle<Map> map) { 960 Handle<Map> map) {
958 CALL_HEAP_FUNCTION(isolate(), 961 CALL_HEAP_FUNCTION(isolate(),
959 isolate()->heap()->CopyFixedArrayWithMap(*array, *map), 962 isolate()->heap()->CopyFixedArrayWithMap(*array, *map),
960 FixedArray); 963 FixedArray);
961 } 964 }
962 965
963 966
964 Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) { 967 Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) {
965 CALL_HEAP_FUNCTION(isolate(), 968 CALL_HEAP_FUNCTION(isolate(),
(...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 return Handle<Object>::null(); 2312 return Handle<Object>::null();
2310 } 2313 }
2311 2314
2312 2315
2313 Handle<Object> Factory::ToBoolean(bool value) { 2316 Handle<Object> Factory::ToBoolean(bool value) {
2314 return value ? true_value() : false_value(); 2317 return value ? true_value() : false_value();
2315 } 2318 }
2316 2319
2317 2320
2318 } } // namespace v8::internal 2321 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698