| OLD | NEW |
| 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 3950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3961 } | 3961 } |
| 3962 | 3962 |
| 3963 | 3963 |
| 3964 MaybeObject* Heap::AllocateSubString(String* buffer, | 3964 MaybeObject* Heap::AllocateSubString(String* buffer, |
| 3965 int start, | 3965 int start, |
| 3966 int end, | 3966 int end, |
| 3967 PretenureFlag pretenure) { | 3967 PretenureFlag pretenure) { |
| 3968 int length = end - start; | 3968 int length = end - start; |
| 3969 if (length <= 0) { | 3969 if (length <= 0) { |
| 3970 return empty_string(); | 3970 return empty_string(); |
| 3971 } else if (length == 1) { | 3971 } |
| 3972 |
| 3973 // Make an attempt to flatten the buffer to reduce access time. |
| 3974 buffer = buffer->TryFlattenGetString(); |
| 3975 |
| 3976 if (length == 1) { |
| 3972 return LookupSingleCharacterStringFromCode(buffer->Get(start)); | 3977 return LookupSingleCharacterStringFromCode(buffer->Get(start)); |
| 3973 } else if (length == 2) { | 3978 } else if (length == 2) { |
| 3974 // Optimization for 2-byte strings often used as keys in a decompression | 3979 // Optimization for 2-byte strings often used as keys in a decompression |
| 3975 // dictionary. Check whether we already have the string in the string | 3980 // dictionary. Check whether we already have the string in the string |
| 3976 // table to prevent creation of many unnecessary strings. | 3981 // table to prevent creation of many unnecessary strings. |
| 3977 uint16_t c1 = buffer->Get(start); | 3982 uint16_t c1 = buffer->Get(start); |
| 3978 uint16_t c2 = buffer->Get(start + 1); | 3983 uint16_t c2 = buffer->Get(start + 1); |
| 3979 return MakeOrFindTwoCharacterString(this, c1, c2); | 3984 return MakeOrFindTwoCharacterString(this, c1, c2); |
| 3980 } | 3985 } |
| 3981 | 3986 |
| 3982 // Make an attempt to flatten the buffer to reduce access time. | |
| 3983 buffer = buffer->TryFlattenGetString(); | |
| 3984 | |
| 3985 if (!FLAG_string_slices || | 3987 if (!FLAG_string_slices || |
| 3986 !buffer->IsFlat() || | 3988 !buffer->IsFlat() || |
| 3987 length < SlicedString::kMinLength || | 3989 length < SlicedString::kMinLength || |
| 3988 pretenure == TENURED) { | 3990 pretenure == TENURED) { |
| 3989 Object* result; | 3991 Object* result; |
| 3990 // WriteToFlat takes care of the case when an indirect string has a | 3992 // WriteToFlat takes care of the case when an indirect string has a |
| 3991 // different encoding from its underlying string. These encodings may | 3993 // different encoding from its underlying string. These encodings may |
| 3992 // differ because of externalization. | 3994 // differ because of externalization. |
| 3993 bool is_one_byte = buffer->IsOneByteRepresentation(); | 3995 bool is_one_byte = buffer->IsOneByteRepresentation(); |
| 3994 { MaybeObject* maybe_result = is_one_byte | 3996 { MaybeObject* maybe_result = is_one_byte |
| (...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4974 // Reset the map for the object. | 4976 // Reset the map for the object. |
| 4975 object->set_map(constructor->initial_map()); | 4977 object->set_map(constructor->initial_map()); |
| 4976 | 4978 |
| 4977 // Reinitialize the object from the constructor map. | 4979 // Reinitialize the object from the constructor map. |
| 4978 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); | 4980 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); |
| 4979 return object; | 4981 return object; |
| 4980 } | 4982 } |
| 4981 | 4983 |
| 4982 | 4984 |
| 4983 MaybeObject* Heap::AllocateStringFromOneByte(Vector<const uint8_t> string, | 4985 MaybeObject* Heap::AllocateStringFromOneByte(Vector<const uint8_t> string, |
| 4984 PretenureFlag pretenure) { | 4986 PretenureFlag pretenure) { |
| 4985 int length = string.length(); | 4987 int length = string.length(); |
| 4986 if (length == 1) { | 4988 if (length == 1) { |
| 4987 return Heap::LookupSingleCharacterStringFromCode(string[0]); | 4989 return Heap::LookupSingleCharacterStringFromCode(string[0]); |
| 4988 } | 4990 } |
| 4989 Object* result; | 4991 Object* result; |
| 4990 { MaybeObject* maybe_result = | 4992 { MaybeObject* maybe_result = |
| 4991 AllocateRawOneByteString(string.length(), pretenure); | 4993 AllocateRawOneByteString(string.length(), pretenure); |
| 4992 if (!maybe_result->ToObject(&result)) return maybe_result; | 4994 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4993 } | 4995 } |
| 4994 | 4996 |
| (...skipping 2966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7961 static_cast<int>(object_sizes_last_time_[index])); | 7963 static_cast<int>(object_sizes_last_time_[index])); |
| 7962 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 7964 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7963 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7965 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 7964 | 7966 |
| 7965 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7967 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 7966 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7968 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 7967 ClearObjectStats(); | 7969 ClearObjectStats(); |
| 7968 } | 7970 } |
| 7969 | 7971 |
| 7970 } } // namespace v8::internal | 7972 } } // namespace v8::internal |
| OLD | NEW |