Speed up adding new properties with a common base shape, bug 704327.

This commit is contained in:
Brian Hackett 2011-11-21 18:33:55 -05:00
parent 299ac2bf87
commit 8f0417b715
3 changed files with 20 additions and 6 deletions

View File

@ -657,11 +657,16 @@ JSObject::addPropertyInternal(JSContext *cx, jsid id,
/* Find or create a property tree node labeled by our arguments. */ /* Find or create a property tree node labeled by our arguments. */
Shape *shape; Shape *shape;
{ {
BaseShape base(getClass(), getParent(), lastProperty()->getObjectFlags(), BaseShape *nbase;
attrs, getter, setter); if (lastProperty()->base()->matchesGetterSetter(getter, setter)) {
BaseShape *nbase = BaseShape::getUnowned(cx, base); nbase = lastProperty()->base();
if (!nbase) } else {
return NULL; BaseShape base(getClass(), getParent(), lastProperty()->getObjectFlags(),
attrs, getter, setter);
nbase = BaseShape::getUnowned(cx, base);
if (!nbase)
return NULL;
}
Shape child(nbase, id, slot, numFixedSlots(), attrs, flags, shortid); Shape child(nbase, id, slot, numFixedSlots(), attrs, flags, shortid);
shape = getChildProperty(cx, lastProperty(), child); shape = getChildProperty(cx, lastProperty(), child);

View File

@ -412,10 +412,13 @@ class BaseShape : public js::gc::Cell
inline BaseShape(Class *clasp, JSObject *parent, uint32 objectFlags); inline BaseShape(Class *clasp, JSObject *parent, uint32 objectFlags);
inline BaseShape(Class *clasp, JSObject *parent, uint32 objectFlags, inline BaseShape(Class *clasp, JSObject *parent, uint32 objectFlags,
uint8 attrs, js::PropertyOp rawGetter, js::StrictPropertyOp rawSetter); uint8 attrs, PropertyOp rawGetter, StrictPropertyOp rawSetter);
bool isOwned() const { return !!(flags & OWNED_SHAPE); } bool isOwned() const { return !!(flags & OWNED_SHAPE); }
inline bool matchesGetterSetter(PropertyOp rawGetter,
StrictPropertyOp rawSetter) const;
inline void adoptUnowned(UnownedBaseShape *other); inline void adoptUnowned(UnownedBaseShape *other);
inline void setOwned(UnownedBaseShape *unowned); inline void setOwned(UnownedBaseShape *unowned);

View File

@ -108,6 +108,12 @@ BaseShape::BaseShape(Class *clasp, JSObject *parent, uint32 objectFlags,
flags |= HAS_SETTER_OBJECT; flags |= HAS_SETTER_OBJECT;
} }
inline bool
BaseShape::matchesGetterSetter(PropertyOp rawGetter, StrictPropertyOp rawSetter) const
{
return rawGetter == this->rawGetter && rawSetter == this->rawSetter;
}
inline void inline void
BaseShape::setParent(JSObject *obj) BaseShape::setParent(JSObject *obj)
{ {