diff --git a/layout/style/ServoBindings.cpp b/layout/style/ServoBindings.cpp index d6e03d1f3972..53eec7150d07 100644 --- a/layout/style/ServoBindings.cpp +++ b/layout/style/ServoBindings.cpp @@ -709,10 +709,24 @@ Gecko_CreateGradient(uint8_t aShape, void Gecko_EnsureTArrayCapacity(void* aArray, size_t aCapacity, size_t aElemSize) { - auto base = reinterpret_cast *>(aArray); + auto base = + reinterpret_cast *>(aArray); + base->EnsureCapacity(aCapacity, aElemSize); } +void +Gecko_ClearPODTArray(void* aArray, size_t aElementSize, size_t aElementAlign) +{ + auto base = + reinterpret_cast *>(aArray); + + base->template ShiftData(0, base->Length(), 0, + aElementSize, aElementAlign); +} + void Gecko_EnsureImageLayersLength(nsStyleImageLayers* aLayers, size_t aLen) { diff --git a/layout/style/ServoBindings.h b/layout/style/ServoBindings.h index b9298944b9c2..195600f1c93e 100644 --- a/layout/style/ServoBindings.h +++ b/layout/style/ServoBindings.h @@ -225,6 +225,11 @@ void Gecko_StoreStyleDifference(RawGeckoNode* node, nsChangeHint change); // friend function declaration in nsTArray.h void Gecko_EnsureTArrayCapacity(void* array, size_t capacity, size_t elem_size); +// Same here, `array` must be an nsTArray, for some T. +// +// Important note: Only valid for POD types, since destructors won't be run +// otherwise. This is ensured with rust traits for the relevant structs. +void Gecko_ClearPODTArray(void* array, size_t elem_size, size_t elem_align); void Gecko_EnsureImageLayersLength(nsStyleImageLayers* layers, size_t len); diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index 2fbd16c599db..2054b731abf3 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -328,7 +328,13 @@ struct nsTArray_SafeElementAtHelper, Derived> } }; -extern "C" void Gecko_EnsureTArrayCapacity(void* aArray, size_t aCapacity, size_t aElemSize); +// Servo bindings. +extern "C" void Gecko_EnsureTArrayCapacity(void* aArray, + size_t aCapacity, + size_t aElementSize); +extern "C" void Gecko_ClearPODTArray(void* aArray, + size_t aElementSize, + size_t aElementAlign); MOZ_NORETURN MOZ_COLD void InvalidArrayIndex_CRASH(size_t aIndex, size_t aLength); @@ -346,7 +352,10 @@ class nsTArray_base // the same free(). template friend class nsTArray_base; - friend void Gecko_EnsureTArrayCapacity(void* aArray, size_t aCapacity, size_t aElemSize); + friend void Gecko_EnsureTArrayCapacity(void* aArray, size_t aCapacity, + size_t aElemSize); + friend void Gecko_ClearPODTArray(void* aTArray, size_t aElementSize, + size_t aElementAlign); protected: typedef nsTArrayHeader Header;