Chromium Code Reviews| Index: src/layout-descriptor-inl.h |
| diff --git a/src/layout-descriptor-inl.h b/src/layout-descriptor-inl.h |
| index ceee09a8105603102d201b8d812cc7f0ec194325..248bd00f2fe93ee19477ae90b37cd7b9d0b13344 100644 |
| --- a/src/layout-descriptor-inl.h |
| +++ b/src/layout-descriptor-inl.h |
| @@ -154,6 +154,61 @@ LayoutDescriptor* LayoutDescriptor::cast_gc_safe(Object* object) { |
| } |
| +int LayoutDescriptor::CalculateCapacity(Map* map, DescriptorArray* descriptors, |
| + int num_descriptors) { |
| + int inobject_properties = map->inobject_properties(); |
| + if (inobject_properties == 0) return 0; |
| + |
| + DCHECK(num_descriptors <= descriptors->number_of_descriptors()); |
|
Toon Verwaest
2015/03/30 11:42:25
_LE
Igor Sheludko
2015/03/30 16:01:29
Done.
|
| + |
| + int layout_descriptor_length; |
| + const int kMaxWordsPerField = kDoubleSize / kPointerSize; |
| + |
| + if (num_descriptors <= kSmiValueSize / kMaxWordsPerField) { |
| + // Even in the "worst" case (all fields are doubles) it would fit into |
| + // a Smi, so no need to calculate length. |
| + layout_descriptor_length = kSmiValueSize; |
| + |
| + } else { |
| + layout_descriptor_length = 0; |
| + |
| + for (int i = 0; i < num_descriptors; i++) { |
| + PropertyDetails details = descriptors->GetDetails(i); |
| + if (!InobjectUnboxedField(inobject_properties, details)) continue; |
| + int field_index = details.field_index(); |
| + int field_width_in_words = details.field_width_in_words(); |
| + layout_descriptor_length = |
| + Max(layout_descriptor_length, field_index + field_width_in_words); |
| + } |
| + } |
| + layout_descriptor_length = Min(layout_descriptor_length, inobject_properties); |
| + return layout_descriptor_length; |
| +} |
| + |
| + |
| +LayoutDescriptor* LayoutDescriptor::Initialize( |
| + LayoutDescriptor* layout_descriptor, Map* map, DescriptorArray* descriptors, |
| + int num_descriptors) { |
| + DisallowHeapAllocation no_allocation; |
| + int inobject_properties = map->inobject_properties(); |
| + |
| + for (int i = 0; i < num_descriptors; i++) { |
| + PropertyDetails details = descriptors->GetDetails(i); |
| + if (!InobjectUnboxedField(inobject_properties, details)) { |
| + DCHECK(details.location() != kField || |
| + layout_descriptor->IsTagged(details.field_index())); |
| + continue; |
| + } |
| + int field_index = details.field_index(); |
| + layout_descriptor = layout_descriptor->SetRawData(field_index); |
| + if (details.field_width_in_words() > 1) { |
| + layout_descriptor = layout_descriptor->SetRawData(field_index + 1); |
| + } |
| + } |
| + return layout_descriptor; |
| +} |
| + |
| + |
| // InobjectPropertiesHelper is a helper class for querying whether inobject |
| // property at offset is Double or not. |
| LayoutDescriptorHelper::LayoutDescriptorHelper(Map* map) |