Commit ff54f31c authored by Jan de Mooij's avatar Jan de Mooij
Browse files

Bug 1805430 part 2 - Optimize generateNewDictionaryShape a bit. r=jonco

Adds a constructor that takes the object for which we want to create a new shape,
so that we can get rid of some roots.

Differential Revision: https://phabricator.services.mozilla.com/D164572
parent 8556591d
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -986,13 +986,7 @@ bool NativeObject::generateNewDictionaryShape(JSContext* cx,

  MOZ_ASSERT(obj->inDictionaryMode());

  Rooted<BaseShape*> base(cx, obj->shape()->base());
  Rooted<DictionaryPropMap*> map(cx, obj->dictionaryShape()->propMap());
  uint32_t mapLength = obj->shape()->propMapLength();

  Shape* shape =
      DictionaryShape::new_(cx, base, obj->shape()->objectFlags(),
                            obj->shape()->numFixedSlots(), map, mapLength);
  Shape* shape = DictionaryShape::new_(cx, obj);
  if (!shape) {
    return false;
  }
@@ -1128,6 +1122,18 @@ DictionaryShape* DictionaryShape::new_(JSContext* cx, Handle<BaseShape*> base,
                                      mapLength);
}

DictionaryShape::DictionaryShape(NativeObject* nobj)
    : DictionaryShape(nobj->shape()->base(), nobj->shape()->objectFlags(),
                      nobj->shape()->numFixedSlots(),
                      nobj->dictionaryShape()->propMap(),
                      nobj->shape()->propMapLength()) {}

// static
DictionaryShape* DictionaryShape::new_(JSContext* cx,
                                       Handle<NativeObject*> obj) {
  return cx->newCell<DictionaryShape>(obj);
}

// static
ProxyShape* ProxyShape::new_(JSContext* cx, Handle<BaseShape*> base,
                             ObjectFlags objectFlags) {
+4 −2
Original line number Diff line number Diff line
@@ -511,7 +511,7 @@ class NativeShape : public Shape {
class SharedShape : public NativeShape {
  friend class js::gc::CellAllocator;
  SharedShape(BaseShape* base, ObjectFlags objectFlags, uint32_t nfixed,
              PropMap* map, uint32_t mapLength)
              SharedPropMap* map, uint32_t mapLength)
      : NativeShape(Kind::Shared, base, objectFlags, nfixed, map, mapLength) {
    initSmallSlotSpan();
  }
@@ -622,11 +622,12 @@ class DictionaryShape : public NativeShape {
  friend class NativeObject;

  DictionaryShape(BaseShape* base, ObjectFlags objectFlags, uint32_t nfixed,
                  PropMap* map, uint32_t mapLength)
                  DictionaryPropMap* map, uint32_t mapLength)
      : NativeShape(Kind::Dictionary, base, objectFlags, nfixed, map,
                    mapLength) {
    MOZ_ASSERT(map);
  }
  explicit DictionaryShape(NativeObject* nobj);

  // Methods to set fields of a new dictionary shape. Must not be used for
  // shapes that might have been exposed to script.
@@ -648,6 +649,7 @@ class DictionaryShape : public NativeShape {
                               ObjectFlags objectFlags, uint32_t nfixed,
                               Handle<DictionaryPropMap*> map,
                               uint32_t mapLength);
  static DictionaryShape* new_(JSContext* cx, Handle<NativeObject*> obj);

  DictionaryPropMap* propMap() const {
    MOZ_ASSERT(isDictionary());