mirror of
https://github.com/status-im/react-native.git
synced 2025-02-05 06:04:15 +00:00
Don't preallocate child lists
Reviewed By: emilsjolander Differential Revision: D4078012 fbshipit-source-id: 7cdcab03ec4067550a5fee5e1baea14344f3a8f9
This commit is contained in:
parent
942f724166
commit
d932c96ddc
@ -195,7 +195,7 @@ int32_t CSSNodeGetInstanceCount(void) {
|
|||||||
|
|
||||||
void CSSNodeInit(const CSSNodeRef node) {
|
void CSSNodeInit(const CSSNodeRef node) {
|
||||||
node->parent = NULL;
|
node->parent = NULL;
|
||||||
node->children = CSSNodeListNew(4);
|
node->children = NULL;
|
||||||
node->hasNewLayout = true;
|
node->hasNewLayout = true;
|
||||||
node->isDirty = false;
|
node->isDirty = false;
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ static void _CSSNodeMarkDirty(const CSSNodeRef node) {
|
|||||||
|
|
||||||
void CSSNodeInsertChild(const CSSNodeRef node, const CSSNodeRef child, const uint32_t index) {
|
void CSSNodeInsertChild(const CSSNodeRef node, const CSSNodeRef child, const uint32_t index) {
|
||||||
CSS_ASSERT(child->parent == NULL, "Child already has a parent, it must be removed first.");
|
CSS_ASSERT(child->parent == NULL, "Child already has a parent, it must be removed first.");
|
||||||
CSSNodeListInsert(node->children, child, index);
|
CSSNodeListInsert(&node->children, child, index);
|
||||||
child->parent = node;
|
child->parent = node;
|
||||||
_CSSNodeMarkDirty(node);
|
_CSSNodeMarkDirty(node);
|
||||||
}
|
}
|
||||||
|
@ -28,19 +28,32 @@ CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CSSNodeListFree(const CSSNodeListRef list) {
|
void CSSNodeListFree(const CSSNodeListRef list) {
|
||||||
free(list->items);
|
if (list) {
|
||||||
free(list);
|
free(list->items);
|
||||||
|
free(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t CSSNodeListCount(const CSSNodeListRef list) {
|
uint32_t CSSNodeListCount(const CSSNodeListRef list) {
|
||||||
return list->count;
|
if (list) {
|
||||||
|
return list->count;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSSNodeListAdd(const CSSNodeListRef list, const CSSNodeRef node) {
|
void CSSNodeListAdd(CSSNodeListRef *listp, const CSSNodeRef node) {
|
||||||
CSSNodeListInsert(list, node, list->count);
|
if (!*listp) {
|
||||||
|
*listp = CSSNodeListNew(4);
|
||||||
|
}
|
||||||
|
CSSNodeListInsert(listp, node, (*listp)->count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSSNodeListInsert(const CSSNodeListRef list, const CSSNodeRef node, const uint32_t index) {
|
void CSSNodeListInsert(CSSNodeListRef *listp, const CSSNodeRef node, const uint32_t index) {
|
||||||
|
if (!*listp) {
|
||||||
|
*listp = CSSNodeListNew(4);
|
||||||
|
}
|
||||||
|
CSSNodeListRef list = *listp;
|
||||||
|
|
||||||
if (list->count == list->capacity) {
|
if (list->count == list->capacity) {
|
||||||
list->capacity *= 2;
|
list->capacity *= 2;
|
||||||
list->items = realloc(list->items, sizeof(void *) * list->capacity);
|
list->items = realloc(list->items, sizeof(void *) * list->capacity);
|
||||||
|
@ -24,8 +24,8 @@ typedef struct CSSNodeList *CSSNodeListRef;
|
|||||||
CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity);
|
CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity);
|
||||||
void CSSNodeListFree(const CSSNodeListRef list);
|
void CSSNodeListFree(const CSSNodeListRef list);
|
||||||
uint32_t CSSNodeListCount(const CSSNodeListRef list);
|
uint32_t CSSNodeListCount(const CSSNodeListRef list);
|
||||||
void CSSNodeListAdd(const CSSNodeListRef list, const CSSNodeRef node);
|
void CSSNodeListAdd(CSSNodeListRef *listp, const CSSNodeRef node);
|
||||||
void CSSNodeListInsert(const CSSNodeListRef list, const CSSNodeRef node, const uint32_t index);
|
void CSSNodeListInsert(CSSNodeListRef *listp, const CSSNodeRef node, const uint32_t index);
|
||||||
CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index);
|
CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index);
|
||||||
CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node);
|
CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node);
|
||||||
CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index);
|
CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user