mirror of
https://github.com/status-im/react-native.git
synced 2025-02-27 16:40:38 +00:00
Lazy create children list when first child is added
Summary: We don't need to allocate a list for every node since leaf nodes don't have children. Reviewed By: emilsjolander Differential Revision: D4130818 fbshipit-source-id: 80d3e98fce9d2daa0676fd1cbed0e81edcf7adb3
This commit is contained in:
parent
96a581f6c2
commit
a320b0ab19
@ -62,8 +62,6 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
||||
if (mNativePointer == 0) {
|
||||
throw new IllegalStateException("Failed to allocate native memory");
|
||||
}
|
||||
|
||||
mChildren = new ArrayList<>(4);
|
||||
}
|
||||
|
||||
private native void jni_CSSNodeFree(long nativePointer);
|
||||
@ -98,7 +96,7 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
||||
|
||||
@Override
|
||||
public int getChildCount() {
|
||||
return mChildren.size();
|
||||
return mChildren == null ? 0 : mChildren.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,6 +111,9 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
||||
throw new IllegalStateException("Child already has a parent, it must be removed first.");
|
||||
}
|
||||
|
||||
if (mChildren == null) {
|
||||
mChildren = new ArrayList<>(4);
|
||||
}
|
||||
mChildren.add(i, child);
|
||||
child.mParent = this;
|
||||
jni_CSSNodeInsertChild(mNativePointer, child.mNativePointer, i);
|
||||
@ -136,7 +137,7 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
||||
|
||||
@Override
|
||||
public int indexOf(CSSNode child) {
|
||||
return mChildren.indexOf(child);
|
||||
return mChildren == null ? -1 : mChildren.indexOf(child);
|
||||
}
|
||||
|
||||
private native void jni_CSSNodeSetIsTextNode(long nativePointer, boolean isTextNode);
|
||||
|
Loading…
x
Reference in New Issue
Block a user