Bug 1285235 - Add bindings for growing nsTArrays; r=bholley
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -13,16 +13,17 @@
#include "nsDOMTokenList.h"
#include "nsIDOMNode.h"
#include "nsIDocument.h"
#include "nsINode.h"
#include "nsIPrincipal.h"
#include "nsNameSpaceManager.h"
#include "nsString.h"
#include "nsStyleStruct.h"
+#include "nsTArray.h"
#include "nsStyleUtil.h"
#include "StyleStructContext.h"
#include "mozilla/EventStates.h"
#include "mozilla/dom/Element.h"
uint32_t
Gecko_ChildrenCount(RawGeckoNode* aNode)
@@ -555,16 +556,22 @@ Gecko_CreateGradient(uint8_t aShape,
for (uint32_t i = 0; i < aStopCount; i++) {
result->mStops.AppendElement(dummyStop);
}
return result;
}
+void
+Gecko_EnsureTArrayCapacity(void* aArray, size_t aCapacity, size_t aElemSize) {
+ auto base = reinterpret_cast<nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils> *>(aArray);
+ base->EnsureCapacity<nsTArrayInfallibleAllocator>(aCapacity, aElemSize);
+}
+
#define STYLE_STRUCT(name, checkdata_cb) \
\
void \
Gecko_Construct_nsStyle##name(nsStyle##name* ptr) \
{ \
new (ptr) nsStyle##name(StyleStructContext::ServoContext()); \
} \
\
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -176,16 +176,21 @@ void Gecko_SetMozBinding(nsStyleDisplay*
ThreadSafePrincipalHolder* principal);
void Gecko_CopyMozBindingFrom(nsStyleDisplay* des, const nsStyleDisplay* src);
// Dirtiness tracking.
uint32_t Gecko_GetNodeFlags(RawGeckoNode* node);
void Gecko_SetNodeFlags(RawGeckoNode* node, uint32_t flags);
void Gecko_UnsetNodeFlags(RawGeckoNode* node, uint32_t flags);
+// `array` must be an nsTArray
+// If changing this signature, please update the
+// friend function declaration in nsTArray.h
+void Gecko_EnsureTArrayCapacity(void* array, size_t capacity, size_t elem_size);
+
// Styleset and Stylesheet management.
//
// TODO: Make these return already_AddRefed and UniquePtr when the binding
// generator is smart enough to handle them.
RawServoStyleSheet* Servo_StylesheetFromUTF8Bytes(
const uint8_t* bytes, uint32_t length,
mozilla::css::SheetParsingMode parsing_mode,
ThreadSafeURIHolder* base,
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -331,29 +331,32 @@ struct nsTArray_SafeElementAtHelper<mozi
{
if (aIndex < static_cast<const Derived*>(this)->Length()) {
return static_cast<const Derived*>(this)->ElementAt(aIndex);
}
return nullptr;
}
};
+extern "C" void Gecko_EnsureTArrayCapacity(void* aArray, size_t aCapacity, size_t aElemSize);
+
//
// This class serves as a base class for nsTArray. It shouldn't be used
// directly. It holds common implementation code that does not depend on the
// element type of the nsTArray.
//
template<class Alloc, class Copy>
class nsTArray_base
{
// Allow swapping elements with |nsTArray_base|s created using a
// different allocator. This is kosher because all allocators use
// the same free().
template<class Allocator, class Copier>
friend class nsTArray_base;
+ friend void Gecko_EnsureTArrayCapacity(void* aArray, size_t aCapacity, size_t aElemSize);
protected:
typedef nsTArrayHeader Header;
public:
typedef size_t size_type;
typedef size_t index_type;