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) {
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
// descriptor array that will contain an elements transition.
......
......@@ -1779,12 +1779,12 @@ MaybeObject* JSObject::ReplaceSlowProperty(String* name,
}
MaybeObject* JSObject::ConvertDescriptorToFieldAndMapTransition(
MaybeObject* JSObject::ConvertTransitionToMapTransition(
int transition_index,
String* name,
Object* new_value,
PropertyAttributes attributes) {
Map* old_map = map();
FixedArray* old_properties = properties();
Object* result;
MaybeObject* maybe_result =
......@@ -1797,23 +1797,10 @@ MaybeObject* JSObject::ConvertDescriptorToFieldAndMapTransition(
// with the map of "new Object()" cannot have transitions in the first place.
ASSERT(map() != GetIsolate()->empty_object_map());
TransitionArray* new_transitions;
MaybeObject* maybe_new_transitions = old_map->AddTransition(name, map());
if (!maybe_new_transitions->To(&new_transitions)) {
// Undo changes and return failure.
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;
}
// TODO(verwaest): From here on we lose existing map transitions, causing
// invalid back pointers. This will change once we can store multiple
// transitions with the same key.
old_map->SetTransition(transition_index, map());
map()->SetBackPointer(old_map);
return result;
}
......@@ -2906,9 +2893,8 @@ MaybeObject* JSObject::SetPropertyForResult(LookupResult* result,
}
// Otherwise, replace with a map transition to a new map with a FIELD,
// even if the value is a constant function.
return self->ConvertDescriptorToFieldAndMapTransition(*name,
*value,
attributes);
return ConvertTransitionToMapTransition(
result->GetTransitionIndex(), *name, *value, attributes);
}
case HANDLER:
case NONEXISTENT:
......@@ -3023,7 +3009,8 @@ MaybeObject* JSObject::SetLocalPropertyIgnoreAttributes(
// Was transition to CONSTANT_FUNCTION. Replace with a map transition to a
// 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 NONEXISTENT:
......
......@@ -1938,19 +1938,15 @@ class JSObject: public JSReceiver {
MUST_USE_RESULT MaybeObject* TransitionElementsKind(ElementsKind to_kind);
// Converts a descriptor of any other type to a real field,
// backed by the properties array. Descriptors of visible
// types, such as CONSTANT_FUNCTION, keep their enumeration order.
// 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(
// Replaces an existing transition with a transition to a map with a FIELD.
MUST_USE_RESULT MaybeObject* ConvertTransitionToMapTransition(
int transition_index,
String* name,
Object* new_value,
PropertyAttributes attributes);
// Converts a descriptor of any other type to a real field,
// backed by the properties array. Descriptors of visible
// types, such as CONSTANT_FUNCTION, keep their enumeration order.
// Converts a descriptor of any other type to a real field, backed by the
// properties array.
MUST_USE_RESULT MaybeObject* ConvertDescriptorToField(
String* name,
Object* new_value,
......@@ -4819,8 +4815,8 @@ class Map: public HeapObject {
MUST_USE_RESULT inline MaybeObject* set_elements_transition_map(
Map* transitioned_map);
inline TransitionArray* transitions();
MUST_USE_RESULT inline MaybeObject* AddTransition(String* key,
Object* value);
inline void SetTransition(int index, Object* value);
MUST_USE_RESULT inline MaybeObject* AddTransition(String* key, Object* value);
MUST_USE_RESULT inline MaybeObject* set_transitions(
TransitionArray* transitions);
inline void ClearTransitions(Heap* heap,
......
......@@ -330,6 +330,11 @@ class LookupResult BASE_EMBEDDED {
return Map::cast(map->transitions()->GetValue(number_));
}
int GetTransitionIndex() {
ASSERT(IsTransition());
return number_;
}
int GetFieldIndex() {
ASSERT(lookup_type_ == DESCRIPTOR_TYPE);
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