Remove init from api

Reviewed By: gkassabli

Differential Revision: D4276177

fbshipit-source-id: c4404d0534f381dfacee0625b2847d38de58e038
This commit is contained in:
Emil Sjolander 2016-12-06 14:37:54 -08:00 committed by Facebook Github Bot
parent d3065f6895
commit a47678b3e9
2 changed files with 51 additions and 52 deletions

View File

@ -185,57 +185,7 @@ static inline float YGComputedEdgeValue(const float edges[YGEdgeCount],
return defaultValue;
}
int32_t gNodeInstanceCount = 0;
YGNodeRef YGNodeNew(void) {
const YGNodeRef node = gYGCalloc(1, sizeof(YGNode));
YG_ASSERT(node, "Could not allocate memory for node");
gNodeInstanceCount++;
YGNodeInit(node);
return node;
}
void YGNodeFree(const YGNodeRef node) {
if (node->parent) {
YGNodeListDelete(node->parent->children, node);
node->parent = NULL;
}
const uint32_t childCount = YGNodeChildCount(node);
for (uint32_t i = 0; i < childCount; i++) {
const YGNodeRef child = YGNodeGetChild(node, i);
child->parent = NULL;
}
YGNodeListFree(node->children);
gYGFree(node);
gNodeInstanceCount--;
}
void YGNodeFreeRecursive(const YGNodeRef root) {
while (YGNodeChildCount(root) > 0) {
const YGNodeRef child = YGNodeGetChild(root, 0);
YGNodeRemoveChild(root, child);
YGNodeFreeRecursive(child);
}
YGNodeFree(root);
}
void YGNodeReset(const YGNodeRef node) {
YG_ASSERT(YGNodeChildCount(node) == 0, "Cannot reset a node which still has children attached");
YG_ASSERT(node->parent == NULL, "Cannot reset a node still attached to a parent");
YGNodeListFree(node->children);
memset(node, 0, sizeof(YGNode));
YGNodeInit(node);
}
int32_t YGNodeGetInstanceCount(void) {
return gNodeInstanceCount;
}
void YGNodeInit(const YGNodeRef node) {
static void YGNodeInit(const YGNodeRef node) {
node->parent = NULL;
node->children = NULL;
node->hasNewLayout = true;
@ -289,6 +239,56 @@ void YGNodeInit(const YGNodeRef node) {
node->layout.cachedLayout.computedHeight = -1;
}
int32_t gNodeInstanceCount = 0;
YGNodeRef YGNodeNew(void) {
const YGNodeRef node = gYGCalloc(1, sizeof(YGNode));
YG_ASSERT(node, "Could not allocate memory for node");
gNodeInstanceCount++;
YGNodeInit(node);
return node;
}
void YGNodeFree(const YGNodeRef node) {
if (node->parent) {
YGNodeListDelete(node->parent->children, node);
node->parent = NULL;
}
const uint32_t childCount = YGNodeChildCount(node);
for (uint32_t i = 0; i < childCount; i++) {
const YGNodeRef child = YGNodeGetChild(node, i);
child->parent = NULL;
}
YGNodeListFree(node->children);
gYGFree(node);
gNodeInstanceCount--;
}
void YGNodeFreeRecursive(const YGNodeRef root) {
while (YGNodeChildCount(root) > 0) {
const YGNodeRef child = YGNodeGetChild(root, 0);
YGNodeRemoveChild(root, child);
YGNodeFreeRecursive(child);
}
YGNodeFree(root);
}
void YGNodeReset(const YGNodeRef node) {
YG_ASSERT(YGNodeChildCount(node) == 0, "Cannot reset a node which still has children attached");
YG_ASSERT(node->parent == NULL, "Cannot reset a node still attached to a parent");
YGNodeListFree(node->children);
memset(node, 0, sizeof(YGNode));
YGNodeInit(node);
}
int32_t YGNodeGetInstanceCount(void) {
return gNodeInstanceCount;
}
static void YGNodeMarkDirtyInternal(const YGNodeRef node) {
if (!node->isDirty) {
node->isDirty = true;

View File

@ -54,7 +54,6 @@ typedef void (*YGFree)(void *ptr);
// YGNode
WIN_EXPORT YGNodeRef YGNodeNew(void);
WIN_EXPORT void YGNodeInit(const YGNodeRef node);
WIN_EXPORT void YGNodeFree(const YGNodeRef node);
WIN_EXPORT void YGNodeFreeRecursive(const YGNodeRef node);
WIN_EXPORT void YGNodeReset(const YGNodeRef node);