OLD | NEW |
---|---|
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 "src/factory.h" | 5 #include "src/factory.h" |
6 | 6 |
7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 } | 663 } |
664 | 664 |
665 | 665 |
666 MaybeHandle<String> Factory::NewExternalStringFromOneByte( | 666 MaybeHandle<String> Factory::NewExternalStringFromOneByte( |
667 const ExternalOneByteString::Resource* resource) { | 667 const ExternalOneByteString::Resource* resource) { |
668 size_t length = resource->length(); | 668 size_t length = resource->length(); |
669 if (length > static_cast<size_t>(String::kMaxLength)) { | 669 if (length > static_cast<size_t>(String::kMaxLength)) { |
670 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String); | 670 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String); |
671 } | 671 } |
672 | 672 |
673 Handle<Map> map = external_one_byte_string_map(); | 673 Handle<Map> map; |
674 if (resource->isCompressible()) { | |
675 map = short_external_one_byte_string_map(); | |
Yang
2015/12/17 11:41:53
Please add a TODO to rename this to "uncached_exte
hajimehoshi
2016/01/05 08:07:44
Done.
| |
676 } else { | |
677 map = external_one_byte_string_map(); | |
678 } | |
674 Handle<ExternalOneByteString> external_string = | 679 Handle<ExternalOneByteString> external_string = |
675 New<ExternalOneByteString>(map, NEW_SPACE); | 680 New<ExternalOneByteString>(map, NEW_SPACE); |
676 external_string->set_length(static_cast<int>(length)); | 681 external_string->set_length(static_cast<int>(length)); |
677 external_string->set_hash_field(String::kEmptyHashField); | 682 external_string->set_hash_field(String::kEmptyHashField); |
678 external_string->set_resource(resource); | 683 external_string->set_resource(resource); |
679 | 684 |
680 return external_string; | 685 return external_string; |
681 } | 686 } |
682 | 687 |
683 | 688 |
684 MaybeHandle<String> Factory::NewExternalStringFromTwoByte( | 689 MaybeHandle<String> Factory::NewExternalStringFromTwoByte( |
685 const ExternalTwoByteString::Resource* resource) { | 690 const ExternalTwoByteString::Resource* resource) { |
686 size_t length = resource->length(); | 691 size_t length = resource->length(); |
687 if (length > static_cast<size_t>(String::kMaxLength)) { | 692 if (length > static_cast<size_t>(String::kMaxLength)) { |
688 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String); | 693 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String); |
689 } | 694 } |
690 | 695 |
691 // For small strings we check whether the resource contains only | 696 // For small strings we check whether the resource contains only |
692 // one byte characters. If yes, we use a different string map. | 697 // one byte characters. If yes, we use a different string map. |
693 static const size_t kOneByteCheckLengthLimit = 32; | 698 static const size_t kOneByteCheckLengthLimit = 32; |
694 bool is_one_byte = length <= kOneByteCheckLengthLimit && | 699 bool is_one_byte = length <= kOneByteCheckLengthLimit && |
695 String::IsOneByte(resource->data(), static_cast<int>(length)); | 700 String::IsOneByte(resource->data(), static_cast<int>(length)); |
696 Handle<Map> map = is_one_byte ? | 701 Handle<Map> map; |
697 external_string_with_one_byte_data_map() : external_string_map(); | 702 if (resource->isCompressible()) { |
703 map = is_one_byte ? short_external_string_with_one_byte_data_map() | |
704 : short_external_string_map(); | |
705 } else { | |
706 map = is_one_byte ? external_string_with_one_byte_data_map() | |
707 : external_string_map(); | |
708 } | |
698 Handle<ExternalTwoByteString> external_string = | 709 Handle<ExternalTwoByteString> external_string = |
699 New<ExternalTwoByteString>(map, NEW_SPACE); | 710 New<ExternalTwoByteString>(map, NEW_SPACE); |
700 external_string->set_length(static_cast<int>(length)); | 711 external_string->set_length(static_cast<int>(length)); |
701 external_string->set_hash_field(String::kEmptyHashField); | 712 external_string->set_hash_field(String::kEmptyHashField); |
702 external_string->set_resource(resource); | 713 external_string->set_resource(resource); |
703 | 714 |
704 return external_string; | 715 return external_string; |
705 } | 716 } |
706 | 717 |
707 | 718 |
(...skipping 1612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2320 } | 2331 } |
2321 | 2332 |
2322 | 2333 |
2323 Handle<Object> Factory::ToBoolean(bool value) { | 2334 Handle<Object> Factory::ToBoolean(bool value) { |
2324 return value ? true_value() : false_value(); | 2335 return value ? true_value() : false_value(); |
2325 } | 2336 } |
2326 | 2337 |
2327 | 2338 |
2328 } // namespace internal | 2339 } // namespace internal |
2329 } // namespace v8 | 2340 } // namespace v8 |
OLD | NEW |