// This reusable base class factors out the logic for a resource that is shared // by multiple instances/modules but should only be counted once when computing // about:memory stats.
size_t sizeOfIncludingThisIfNotSeen(mozilla::MallocSizeOf mallocSizeOf,
SeenSet* seen) const { const T* self = static_cast<const T*>(this); typename SeenSet::AddPtr p = seen->lookupForAdd(self); if (p) { return0;
} bool ok = seen->add(p, self);
(void)ok; // oh well return mallocSizeOf(self) + self->sizeOfExcludingThis(mallocSizeOf);
}
};
// ShareableBytes is a reference-counted Vector of bytes.
// Vector is 'final' and cannot be inherited to combine with ShareableBase, so // we need to define a wrapper class with boilerplate methods. template <typename T, size_t MinInlineCapacity, class AllocPolicy> struct ShareableVector
: public ShareableBase<ShareableVector<T, MinInlineCapacity, AllocPolicy>> { using VecT = mozilla::Vector<T, MinInlineCapacity, AllocPolicy>;
// If we succeed in allocating the vector but fail to append something to // it, we need to delete this vector before returning. if (!vector->append(span.data(), span.size())) {
js_free(vector); return nullptr;
}
return vector;
}
};
using ShareableBytes = ShareableVector<uint8_t, 0, SystemAllocPolicy>; using MutableBytes = RefPtr<ShareableBytes>; using SharedBytes = RefPtr<const ShareableBytes>;
struct ShareableChars : public ShareableBase<ShareableChars> {
UniqueChars chars;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.