Introduce CSSNodeGetInstanceCount API

Summary:
- Add CSSNodeGetInstanceCount API to get the number of native instances.
- It makes testing easy.

Reviewed By: emilsjolander

Differential Revision: D3981990

fbshipit-source-id: 98005ae1fc21d4c8802f24030fff9ffb00bd292d
This commit is contained in:
Kazuki Sakamoto
2016-10-07 11:07:50 -07:00
committed by Facebook Github Bot
parent b57abb2f60
commit c233bafeb2
5 changed files with 55 additions and 0 deletions

View File

@@ -129,9 +129,12 @@ computedEdgeValue(const float edges[CSSEdgeCount], const CSSEdge edge, const flo
return defaultValue;
}
static int32_t gNodeInstanceCount = 0;
CSSNodeRef CSSNodeNew() {
const CSSNodeRef node = calloc(1, sizeof(CSSNode));
CSS_ASSERT(node, "Could not allocate memory for node");
gNodeInstanceCount++;
CSSNodeInit(node);
return node;
@@ -140,6 +143,7 @@ CSSNodeRef CSSNodeNew() {
void CSSNodeFree(const CSSNodeRef node) {
CSSNodeListFree(node->children);
free(node);
gNodeInstanceCount--;
}
void CSSNodeFreeRecursive(const CSSNodeRef root) {
@@ -151,6 +155,10 @@ void CSSNodeFreeRecursive(const CSSNodeRef root) {
CSSNodeFree(root);
}
int32_t CSSNodeGetInstanceCount() {
return gNodeInstanceCount;
}
void CSSNodeInit(const CSSNodeRef node) {
node->parent = NULL;
node->children = CSSNodeListNew(4);