Skip to content

Commit

Permalink
Remove init from api
Browse files Browse the repository at this point in the history
Summary: Both New and Reset already call init internally. No reason to expose this function

Reviewed By: gkassabli

Differential Revision: D4276177

fbshipit-source-id: c4404d0534f381dfacee0625b2847d38de58e038
  • Loading branch information
Emil Sjolander authored and Facebook Github Bot committed Dec 6, 2016
1 parent 613590b commit 40371cb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 52 deletions.
102 changes: 51 additions & 51 deletions CSSLayout/Yoga.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion CSSLayout/Yoga.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 40371cb

Please sign in to comment.