Chromium Code Reviews| Index: src/transitions.cc |
| diff --git a/src/transitions.cc b/src/transitions.cc |
| index 96ed870e07b43465bccef7b29abe24b7305f246e..06d6a106e9f2710e3ac38fee3118473e75bd2b16 100644 |
| --- a/src/transitions.cc |
| +++ b/src/transitions.cc |
| @@ -13,10 +13,12 @@ namespace internal { |
| Handle<TransitionArray> TransitionArray::Allocate(Isolate* isolate, |
| - int number_of_transitions) { |
| - Handle<FixedArray> array = |
| - isolate->factory()->NewFixedArray(ToKeyIndex(number_of_transitions)); |
| + int number_of_transitions, |
| + int slack) { |
| + Handle<FixedArray> array = isolate->factory()->NewFixedArray( |
| + LengthFor(number_of_transitions + slack)); |
| array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); |
| + array->set(kTransitionLengthIndex, Smi::FromInt(number_of_transitions)); |
| return Handle<TransitionArray>::cast(array); |
| } |
| @@ -85,21 +87,50 @@ Handle<TransitionArray> TransitionArray::ExtendToFullTransitionArray( |
| } |
| -Handle<TransitionArray> TransitionArray::CopyInsert(Handle<Map> map, |
| - Handle<Name> name, |
| - Handle<Map> target, |
| - SimpleTransitionFlag flag) { |
| +Handle<TransitionArray> TransitionArray::Insert(Handle<Map> map, |
| + Handle<Name> name, |
| + Handle<Map> target, |
| + SimpleTransitionFlag flag) { |
| if (!map->HasTransitionArray()) { |
| return TransitionArray::NewWith(map, name, target, flag); |
| } |
| int number_of_transitions = map->transitions()->number_of_transitions(); |
| - int new_size = number_of_transitions; |
| + int new_nof = number_of_transitions; |
| int insertion_index = map->transitions()->Search(*name); |
| - if (insertion_index == kNotFound) ++new_size; |
| + if (insertion_index == kNotFound) ++new_nof; |
| + |
| + if (new_nof <= map->transitions()->number_of_transitions_storage()) { |
| + DisallowHeapAllocation no_gc; |
| + TransitionArray* array = map->transitions(); |
| + |
| + if (insertion_index != kNotFound) { |
| + if (array->IsSimpleTransition()) { |
| + DCHECK(insertion_index == kSimpleTransitionIndex); |
| + array->set(kSimpleTransitionTarget, *target); |
| + } else { |
| + array->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); |
|
Toon Verwaest
2014/10/23 09:44:34
You can't omit the incremental write barrier if yo
mckev
2014/10/24 02:18:51
Ah.. SetTarget seems more appropriate then.
|
| + } |
| + return handle(array); |
| + } |
| + |
| + array->SetNumberOfTransitions(new_nof); |
| + uint32_t hash = name->Hash(); |
| + for (insertion_index = number_of_transitions; insertion_index > 0; |
| + --insertion_index) { |
| + Name* key = array->GetKey(insertion_index - 1); |
| + if (key->Hash() <= hash) break; |
| + array->NoIncrementalWriteBarrierSet( |
| + insertion_index, key, array->GetTarget(insertion_index - 1)); |
|
Toon Verwaest
2014/10/23 09:44:33
Same here.
|
| + } |
| + array->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); |
|
Toon Verwaest
2014/10/23 09:44:33
Same here.
|
| + return handle(array); |
| + } |
| - Handle<TransitionArray> result = Allocate(map->GetIsolate(), new_size); |
| + Handle<TransitionArray> result = |
| + Allocate(map->GetIsolate(), new_nof, |
| + number_of_transitions < 4 ? 1 : number_of_transitions / 2); |
|
Toon Verwaest
2014/10/23 09:44:33
Please add a helper function to calculate the actu
mckev
2014/10/24 02:18:51
Done.
|
| // The map's transition array may grown smaller during the allocation above as |
| // it was weakly traversed, though it is guaranteed not to disappear. Trim the |
| @@ -111,29 +142,18 @@ Handle<TransitionArray> TransitionArray::CopyInsert(Handle<Map> map, |
| DCHECK(array->number_of_transitions() < number_of_transitions); |
| number_of_transitions = array->number_of_transitions(); |
| - new_size = number_of_transitions; |
| + new_nof = number_of_transitions; |
| insertion_index = array->Search(*name); |
| - if (insertion_index == kNotFound) ++new_size; |
| + if (insertion_index == kNotFound) ++new_nof; |
| - result->Shrink(ToKeyIndex(new_size)); |
| + result->Shrink(ToKeyIndex(new_nof)); |
| } |
| if (array->HasPrototypeTransitions()) { |
| result->SetPrototypeTransitions(array->GetPrototypeTransitions()); |
| } |
| - if (insertion_index != kNotFound) { |
| - for (int i = 0; i < number_of_transitions; ++i) { |
| - if (i != insertion_index) { |
| - result->NoIncrementalWriteBarrierCopyFrom(array, i, i); |
| - } |
| - } |
| - result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); |
| - result->set_back_pointer_storage(array->back_pointer_storage()); |
| - return result; |
| - } |
| - |
| insertion_index = 0; |
| for (; insertion_index < number_of_transitions; ++insertion_index) { |
| if (InsertionPointFound(array->GetKey(insertion_index), *name)) break; |