Reverting the dirty child optimization
Reviewed By: emilsjolander Differential Revision: D6203290 fbshipit-source-id: 8e42abb70e55f0fac90faaa21ecdbe0fbb76ce6b
This commit is contained in:
parent
1dca01b532
commit
0230672275
|
@ -82,8 +82,6 @@ public interface ReactShadowNode<T extends ReactShadowNode> {
|
||||||
|
|
||||||
boolean isDirty();
|
boolean isDirty();
|
||||||
|
|
||||||
boolean hasDirtyDescendants();
|
|
||||||
|
|
||||||
void addChildAt(T child, int i);
|
void addChildAt(T child, int i);
|
||||||
|
|
||||||
T removeChildAt(int i);
|
T removeChildAt(int i);
|
||||||
|
|
|
@ -134,7 +134,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean hasUpdates() {
|
public final boolean hasUpdates() {
|
||||||
return mNodeUpdated || hasNewLayout() || isDirty() || hasDirtyDescendants();
|
return mNodeUpdated || hasNewLayout() || isDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -174,11 +174,6 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
||||||
return mYogaNode != null && mYogaNode.isDirty();
|
return mYogaNode != null && mYogaNode.isDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasDirtyDescendants() {
|
|
||||||
return mYogaNode != null && mYogaNode.hasDirtyDescendants();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addChildAt(ReactShadowNodeImpl child, int i) {
|
public void addChildAt(ReactShadowNodeImpl child, int i) {
|
||||||
if (child.getParent() != null) {
|
if (child.getParent() != null) {
|
||||||
|
|
|
@ -9,11 +9,13 @@
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
import com.facebook.soloader.SoLoader;
|
import com.facebook.soloader.SoLoader;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
@DoNotStrip
|
@DoNotStrip
|
||||||
public class YogaNode {
|
public class YogaNode {
|
||||||
|
@ -196,12 +198,6 @@ public class YogaNode {
|
||||||
return jni_YGNodeIsDirty(mNativePointer);
|
return jni_YGNodeIsDirty(mNativePointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private native boolean jni_YGNodeHasDirtyDescendants(long nativePointer);
|
|
||||||
|
|
||||||
public boolean hasDirtyDescendants() {
|
|
||||||
return jni_YGNodeHasDirtyDescendants(mNativePointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
|
private native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
|
||||||
public void copyStyle(YogaNode srcNode) {
|
public void copyStyle(YogaNode srcNode) {
|
||||||
jni_YGNodeCopyStyle(mNativePointer, srcNode.mNativePointer);
|
jni_YGNodeCopyStyle(mNativePointer, srcNode.mNativePointer);
|
||||||
|
|
|
@ -249,10 +249,6 @@ jboolean jni_YGNodeIsDirty(alias_ref<jobject>, jlong nativePointer) {
|
||||||
return (jboolean) YGNodeIsDirty(_jlong2YGNodeRef(nativePointer));
|
return (jboolean) YGNodeIsDirty(_jlong2YGNodeRef(nativePointer));
|
||||||
}
|
}
|
||||||
|
|
||||||
jboolean jni_YGNodeHasDirtyDescendants(alias_ref<jobject>, jlong nativePointer) {
|
|
||||||
return (jboolean) YGNodeHasDirtyDescendants(_jlong2YGNodeRef(nativePointer));
|
|
||||||
}
|
|
||||||
|
|
||||||
void jni_YGNodeSetHasMeasureFunc(alias_ref<jobject>, jlong nativePointer, jboolean hasMeasureFunc) {
|
void jni_YGNodeSetHasMeasureFunc(alias_ref<jobject>, jlong nativePointer, jboolean hasMeasureFunc) {
|
||||||
YGNodeSetMeasureFunc(_jlong2YGNodeRef(nativePointer), hasMeasureFunc ? YGJNIMeasureFunc : NULL);
|
YGNodeSetMeasureFunc(_jlong2YGNodeRef(nativePointer), hasMeasureFunc ? YGJNIMeasureFunc : NULL);
|
||||||
}
|
}
|
||||||
|
@ -457,7 +453,6 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
|
||||||
YGMakeNativeMethod(jni_YGNodeCalculateLayout),
|
YGMakeNativeMethod(jni_YGNodeCalculateLayout),
|
||||||
YGMakeNativeMethod(jni_YGNodeMarkDirty),
|
YGMakeNativeMethod(jni_YGNodeMarkDirty),
|
||||||
YGMakeNativeMethod(jni_YGNodeIsDirty),
|
YGMakeNativeMethod(jni_YGNodeIsDirty),
|
||||||
YGMakeNativeMethod(jni_YGNodeHasDirtyDescendants),
|
|
||||||
YGMakeNativeMethod(jni_YGNodeSetHasMeasureFunc),
|
YGMakeNativeMethod(jni_YGNodeSetHasMeasureFunc),
|
||||||
YGMakeNativeMethod(jni_YGNodeSetHasBaselineFunc),
|
YGMakeNativeMethod(jni_YGNodeSetHasBaselineFunc),
|
||||||
YGMakeNativeMethod(jni_YGNodeCopyStyle),
|
YGMakeNativeMethod(jni_YGNodeCopyStyle),
|
||||||
|
|
|
@ -123,7 +123,6 @@ typedef struct YGNode {
|
||||||
void *context;
|
void *context;
|
||||||
|
|
||||||
bool isDirty;
|
bool isDirty;
|
||||||
bool hasDirtyDescendants;
|
|
||||||
bool hasNewLayout;
|
bool hasNewLayout;
|
||||||
YGNodeType nodeType;
|
YGNodeType nodeType;
|
||||||
|
|
||||||
|
@ -163,7 +162,6 @@ static const YGNode gYGNodeDefaults = {
|
||||||
.children = NULL,
|
.children = NULL,
|
||||||
.hasNewLayout = true,
|
.hasNewLayout = true,
|
||||||
.isDirty = false,
|
.isDirty = false,
|
||||||
.hasDirtyDescendants = false,
|
|
||||||
.nodeType = YGNodeTypeDefault,
|
.nodeType = YGNodeTypeDefault,
|
||||||
.resolvedDimensions = {[YGDimensionWidth] = &YGValueUndefined,
|
.resolvedDimensions = {[YGDimensionWidth] = &YGValueUndefined,
|
||||||
[YGDimensionHeight] = &YGValueUndefined},
|
[YGDimensionHeight] = &YGValueUndefined},
|
||||||
|
@ -240,8 +238,6 @@ static YGConfig gYGConfigDefaults = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void YGNodeMarkDirtyInternal(const YGNodeRef node);
|
static void YGNodeMarkDirtyInternal(const YGNodeRef node);
|
||||||
static bool YGNodeIsLayoutBoundary(const YGNodeRef node);
|
|
||||||
static void YGNodeMarkHasDirtyDescendants(const YGNodeRef node);
|
|
||||||
|
|
||||||
YGMalloc gYGMalloc = &malloc;
|
YGMalloc gYGMalloc = &malloc;
|
||||||
YGCalloc gYGCalloc = &calloc;
|
YGCalloc gYGCalloc = &calloc;
|
||||||
|
@ -456,33 +452,16 @@ void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src) {
|
||||||
memcpy(dest, src, sizeof(YGConfig));
|
memcpy(dest, src, sizeof(YGConfig));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGNodeMarkHasDirtyDescendants(const YGNodeRef node) {
|
|
||||||
if (node && !node->hasDirtyDescendants) {
|
|
||||||
node->hasDirtyDescendants = true;
|
|
||||||
YGNodeMarkHasDirtyDescendants(node->parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void YGNodeMarkDirtyInternal(const YGNodeRef node) {
|
static void YGNodeMarkDirtyInternal(const YGNodeRef node) {
|
||||||
if (!node->isDirty) {
|
if (!node->isDirty) {
|
||||||
node->isDirty = true;
|
node->isDirty = true;
|
||||||
node->layout.computedFlexBasis = YGUndefined;
|
node->layout.computedFlexBasis = YGUndefined;
|
||||||
if (node->parent) {
|
if (node->parent) {
|
||||||
if (YGNodeIsLayoutBoundary(node->parent)) {
|
YGNodeMarkDirtyInternal(node->parent);
|
||||||
node->parent->isDirty = true; // Because parent lays out the child
|
|
||||||
node->parent->layout.computedFlexBasis = YGUndefined;
|
|
||||||
YGNodeMarkHasDirtyDescendants(node->parent);
|
|
||||||
} else {
|
|
||||||
YGNodeMarkDirtyInternal(node->parent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool YGNodeIsLayoutBoundary(const YGNodeRef node) {
|
|
||||||
return YGNodeStyleGetPositionType(node) == YGPositionTypeAbsolute;
|
|
||||||
}
|
|
||||||
|
|
||||||
void YGNodeSetMeasureFunc(const YGNodeRef node, YGMeasureFunc measureFunc) {
|
void YGNodeSetMeasureFunc(const YGNodeRef node, YGMeasureFunc measureFunc) {
|
||||||
if (measureFunc == NULL) {
|
if (measureFunc == NULL) {
|
||||||
node->measure = NULL;
|
node->measure = NULL;
|
||||||
|
@ -649,10 +628,6 @@ bool YGNodeIsDirty(const YGNodeRef node) {
|
||||||
return node->isDirty;
|
return node->isDirty;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGNodeHasDirtyDescendants(const YGNodeRef node) {
|
|
||||||
return node->hasDirtyDescendants;
|
|
||||||
}
|
|
||||||
|
|
||||||
void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) {
|
void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) {
|
||||||
if (memcmp(&dstNode->style, &srcNode->style, sizeof(YGStyle)) != 0) {
|
if (memcmp(&dstNode->style, &srcNode->style, sizeof(YGStyle)) != 0) {
|
||||||
memcpy(&dstNode->style, &srcNode->style, sizeof(YGStyle));
|
memcpy(&dstNode->style, &srcNode->style, sizeof(YGStyle));
|
||||||
|
@ -3431,6 +3406,7 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
||||||
const char *reason,
|
const char *reason,
|
||||||
const YGConfigRef config) {
|
const YGConfigRef config) {
|
||||||
YGLayout *layout = &node->layout;
|
YGLayout *layout = &node->layout;
|
||||||
|
|
||||||
gDepth++;
|
gDepth++;
|
||||||
|
|
||||||
const bool needToVisitNode =
|
const bool needToVisitNode =
|
||||||
|
@ -3522,26 +3498,6 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
||||||
if (!needToVisitNode && cachedResults != NULL) {
|
if (!needToVisitNode && cachedResults != NULL) {
|
||||||
layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth;
|
layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth;
|
||||||
layout->measuredDimensions[YGDimensionHeight] = cachedResults->computedHeight;
|
layout->measuredDimensions[YGDimensionHeight] = cachedResults->computedHeight;
|
||||||
if (YGNodeHasDirtyDescendants(node)) {
|
|
||||||
const uint32_t childCount = YGNodeListCount(node->children);
|
|
||||||
for (uint32_t i = 0; i < childCount; ++i) {
|
|
||||||
const YGNodeRef child = YGNodeListGet(node->children, i);
|
|
||||||
if (child->isDirty || YGNodeHasDirtyDescendants(child)) {
|
|
||||||
YGLayoutNodeInternal(child,
|
|
||||||
child->layout.cachedLayout.availableWidth,
|
|
||||||
child->layout.cachedLayout.availableHeight,
|
|
||||||
child->layout.direction,
|
|
||||||
child->layout.cachedLayout.widthMeasureMode,
|
|
||||||
child->layout.cachedLayout.heightMeasureMode,
|
|
||||||
cachedResults->computedWidth,
|
|
||||||
cachedResults->computedHeight,
|
|
||||||
performLayout,
|
|
||||||
"layout",
|
|
||||||
child->config
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gPrintChanges && gPrintSkips) {
|
if (gPrintChanges && gPrintSkips) {
|
||||||
printf("%s%d.{[skipped] ", YGSpacer(gDepth), gDepth);
|
printf("%s%d.{[skipped] ", YGSpacer(gDepth), gDepth);
|
||||||
|
@ -3629,7 +3585,6 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
||||||
node->layout.dimensions[YGDimensionHeight] = node->layout.measuredDimensions[YGDimensionHeight];
|
node->layout.dimensions[YGDimensionHeight] = node->layout.measuredDimensions[YGDimensionHeight];
|
||||||
node->hasNewLayout = true;
|
node->hasNewLayout = true;
|
||||||
node->isDirty = false;
|
node->isDirty = false;
|
||||||
node->hasDirtyDescendants = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gDepth--;
|
gDepth--;
|
||||||
|
|
|
@ -101,7 +101,6 @@ WIN_EXPORT void YGNodeCalculateLayout(const YGNodeRef node,
|
||||||
// marking manually.
|
// marking manually.
|
||||||
WIN_EXPORT void YGNodeMarkDirty(const YGNodeRef node);
|
WIN_EXPORT void YGNodeMarkDirty(const YGNodeRef node);
|
||||||
WIN_EXPORT bool YGNodeIsDirty(const YGNodeRef node);
|
WIN_EXPORT bool YGNodeIsDirty(const YGNodeRef node);
|
||||||
WIN_EXPORT bool YGNodeHasDirtyDescendants(const YGNodeRef node);
|
|
||||||
|
|
||||||
WIN_EXPORT void YGNodePrint(const YGNodeRef node, const YGPrintOptions options);
|
WIN_EXPORT void YGNodePrint(const YGNodeRef node, const YGPrintOptions options);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue