Commit 70a61830 authored by verwaest@chromium.org's avatar verwaest@chromium.org

Renamed ConvertDescriptorToFieldAndMapTransition to...

Renamed ConvertDescriptorToFieldAndMapTransition to ConvertTransitionToMapTransition, and let it replace the transition in-place rather than copy the transition array.

Review URL: https://chromiumcodereview.appspot.com/10694155

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12071 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 30569cba
...@@ -3539,6 +3539,10 @@ MaybeObject* Map::AddTransition(String* key, Object* value) { ...@@ -3539,6 +3539,10 @@ MaybeObject* Map::AddTransition(String* key, Object* value) {
return TransitionArray::NewWith(key, value); return TransitionArray::NewWith(key, value);
} }
void Map::SetTransition(int transition_index, Object* value) {
transitions()->SetValue(transition_index, value);
}
// If the map is using the empty descriptor array, install a new empty // If the map is using the empty descriptor array, install a new empty
// descriptor array that will contain an elements transition. // descriptor array that will contain an elements transition.
......
...@@ -1779,12 +1779,12 @@ MaybeObject* JSObject::ReplaceSlowProperty(String* name, ...@@ -1779,12 +1779,12 @@ MaybeObject* JSObject::ReplaceSlowProperty(String* name,
} }
MaybeObject* JSObject::ConvertDescriptorToFieldAndMapTransition( MaybeObject* JSObject::ConvertTransitionToMapTransition(
int transition_index,
String* name, String* name,
Object* new_value, Object* new_value,
PropertyAttributes attributes) { PropertyAttributes attributes) {
Map* old_map = map(); Map* old_map = map();
FixedArray* old_properties = properties();
Object* result; Object* result;
MaybeObject* maybe_result = MaybeObject* maybe_result =
...@@ -1797,23 +1797,10 @@ MaybeObject* JSObject::ConvertDescriptorToFieldAndMapTransition( ...@@ -1797,23 +1797,10 @@ MaybeObject* JSObject::ConvertDescriptorToFieldAndMapTransition(
// with the map of "new Object()" cannot have transitions in the first place. // with the map of "new Object()" cannot have transitions in the first place.
ASSERT(map() != GetIsolate()->empty_object_map()); ASSERT(map() != GetIsolate()->empty_object_map());
TransitionArray* new_transitions; // TODO(verwaest): From here on we lose existing map transitions, causing
MaybeObject* maybe_new_transitions = old_map->AddTransition(name, map()); // invalid back pointers. This will change once we can store multiple
if (!maybe_new_transitions->To(&new_transitions)) { // transitions with the same key.
// Undo changes and return failure. old_map->SetTransition(transition_index, map());
set_map(old_map);
set_properties(old_properties);
return maybe_new_transitions;
}
MaybeObject* transition_added = old_map->set_transitions(new_transitions);
if (transition_added->IsFailure()) {
// Undo changes and return failure.
set_map(old_map);
set_properties(old_properties);
return transition_added;
}
map()->SetBackPointer(old_map); map()->SetBackPointer(old_map);
return result; return result;
} }
...@@ -2906,9 +2893,8 @@ MaybeObject* JSObject::SetPropertyForResult(LookupResult* result, ...@@ -2906,9 +2893,8 @@ MaybeObject* JSObject::SetPropertyForResult(LookupResult* result,
} }
// Otherwise, replace with a map transition to a new map with a FIELD, // Otherwise, replace with a map transition to a new map with a FIELD,
// even if the value is a constant function. // even if the value is a constant function.
return self->ConvertDescriptorToFieldAndMapTransition(*name, return ConvertTransitionToMapTransition(
*value, result->GetTransitionIndex(), *name, *value, attributes);
attributes);
} }
case HANDLER: case HANDLER:
case NONEXISTENT: case NONEXISTENT:
...@@ -3023,7 +3009,8 @@ MaybeObject* JSObject::SetLocalPropertyIgnoreAttributes( ...@@ -3023,7 +3009,8 @@ MaybeObject* JSObject::SetLocalPropertyIgnoreAttributes(
// Was transition to CONSTANT_FUNCTION. Replace with a map transition to a // Was transition to CONSTANT_FUNCTION. Replace with a map transition to a
// new map with a FIELD, even if the value is a function. // new map with a FIELD, even if the value is a function.
return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); return ConvertTransitionToMapTransition(
result.GetTransitionIndex(), name, value, attributes);
} }
case HANDLER: case HANDLER:
case NONEXISTENT: case NONEXISTENT:
......
...@@ -1938,19 +1938,15 @@ class JSObject: public JSReceiver { ...@@ -1938,19 +1938,15 @@ class JSObject: public JSReceiver {
MUST_USE_RESULT MaybeObject* TransitionElementsKind(ElementsKind to_kind); MUST_USE_RESULT MaybeObject* TransitionElementsKind(ElementsKind to_kind);
// Converts a descriptor of any other type to a real field, // Replaces an existing transition with a transition to a map with a FIELD.
// backed by the properties array. Descriptors of visible MUST_USE_RESULT MaybeObject* ConvertTransitionToMapTransition(
// types, such as CONSTANT_FUNCTION, keep their enumeration order. int transition_index,
// Converts the descriptor on the original object's map to a
// map transition, and the the new field is on the object's new map.
MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition(
String* name, String* name,
Object* new_value, Object* new_value,
PropertyAttributes attributes); PropertyAttributes attributes);
// Converts a descriptor of any other type to a real field, // Converts a descriptor of any other type to a real field, backed by the
// backed by the properties array. Descriptors of visible // properties array.
// types, such as CONSTANT_FUNCTION, keep their enumeration order.
MUST_USE_RESULT MaybeObject* ConvertDescriptorToField( MUST_USE_RESULT MaybeObject* ConvertDescriptorToField(
String* name, String* name,
Object* new_value, Object* new_value,
...@@ -4819,8 +4815,8 @@ class Map: public HeapObject { ...@@ -4819,8 +4815,8 @@ class Map: public HeapObject {
MUST_USE_RESULT inline MaybeObject* set_elements_transition_map( MUST_USE_RESULT inline MaybeObject* set_elements_transition_map(
Map* transitioned_map); Map* transitioned_map);
inline TransitionArray* transitions(); inline TransitionArray* transitions();
MUST_USE_RESULT inline MaybeObject* AddTransition(String* key, inline void SetTransition(int index, Object* value);
Object* value); MUST_USE_RESULT inline MaybeObject* AddTransition(String* key, Object* value);
MUST_USE_RESULT inline MaybeObject* set_transitions( MUST_USE_RESULT inline MaybeObject* set_transitions(
TransitionArray* transitions); TransitionArray* transitions);
inline void ClearTransitions(Heap* heap, inline void ClearTransitions(Heap* heap,
......
...@@ -330,6 +330,11 @@ class LookupResult BASE_EMBEDDED { ...@@ -330,6 +330,11 @@ class LookupResult BASE_EMBEDDED {
return Map::cast(map->transitions()->GetValue(number_)); return Map::cast(map->transitions()->GetValue(number_));
} }
int GetTransitionIndex() {
ASSERT(IsTransition());
return number_;
}
int GetFieldIndex() { int GetFieldIndex() {
ASSERT(lookup_type_ == DESCRIPTOR_TYPE); ASSERT(lookup_type_ == DESCRIPTOR_TYPE);
ASSERT(IsField()); ASSERT(IsField());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment