Lazy create children list when first child is added
Summary: @public 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:
committed by
Facebook Github Bot
parent
9c1896043d
commit
01a3881426
@@ -62,8 +62,6 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
|||||||
if (mNativePointer == 0) {
|
if (mNativePointer == 0) {
|
||||||
throw new IllegalStateException("Failed to allocate native memory");
|
throw new IllegalStateException("Failed to allocate native memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
mChildren = new ArrayList<>(4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private native void jni_CSSNodeFree(long nativePointer);
|
private native void jni_CSSNodeFree(long nativePointer);
|
||||||
@@ -98,7 +96,7 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getChildCount() {
|
public int getChildCount() {
|
||||||
return mChildren.size();
|
return mChildren == null ? 0 : mChildren.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -113,6 +111,9 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
|||||||
throw new IllegalStateException("Child already has a parent, it must be removed first.");
|
throw new IllegalStateException("Child already has a parent, it must be removed first.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mChildren == null) {
|
||||||
|
mChildren = new ArrayList<>(4);
|
||||||
|
}
|
||||||
mChildren.add(i, child);
|
mChildren.add(i, child);
|
||||||
child.mParent = this;
|
child.mParent = this;
|
||||||
jni_CSSNodeInsertChild(mNativePointer, child.mNativePointer, i);
|
jni_CSSNodeInsertChild(mNativePointer, child.mNativePointer, i);
|
||||||
@@ -136,7 +137,7 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int indexOf(CSSNode child) {
|
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);
|
private native void jni_CSSNodeSetIsTextNode(long nativePointer, boolean isTextNode);
|
||||||
|
Reference in New Issue
Block a user