Remove isTextNode optimization
Summary: Scrolling through feed and logging when this optimization is hit leads to... 0 logs. If anything this just adds to confusion. It was initially added due to instinct and not data, which was a mistake. I am happy to add some similar optimization in the future if we have data that it is useful in real world situations, currently it just leads to bugs and confusion though. Reviewed By: astreet Differential Revision: D4146785 fbshipit-source-id: e20d780fbd5759b8f38b809e8cadf29cedee82a8
This commit is contained in:
committed by
Facebook Github Bot
parent
b50090a04e
commit
1baa239389
@@ -140,18 +140,6 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
||||
return mChildren == null ? -1 : mChildren.indexOf(child);
|
||||
}
|
||||
|
||||
private native void jni_CSSNodeSetIsTextNode(long nativePointer, boolean isTextNode);
|
||||
@Override
|
||||
public void setIsTextNode(boolean isTextNode) {
|
||||
jni_CSSNodeSetIsTextNode(mNativePointer, isTextNode);
|
||||
}
|
||||
|
||||
private native boolean jni_CSSNodeGetIsTextNode(long nativePointer);
|
||||
@Override
|
||||
public boolean isTextNode() {
|
||||
return jni_CSSNodeGetIsTextNode(mNativePointer);
|
||||
}
|
||||
|
||||
private native void jni_CSSNodeCalculateLayout(long nativePointer);
|
||||
@Override
|
||||
public void calculateLayout(CSSLayoutContext layoutContext) {
|
||||
|
@@ -31,8 +31,6 @@ public interface CSSNodeAPI<CSSNodeType extends CSSNodeAPI> {
|
||||
int indexOf(CSSNodeType child);
|
||||
void setMeasureFunction(MeasureFunction measureFunction);
|
||||
boolean isMeasureDefined();
|
||||
void setIsTextNode(boolean isTextNode);
|
||||
boolean isTextNode();
|
||||
void calculateLayout(CSSLayoutContext layoutContext);
|
||||
boolean isDirty();
|
||||
boolean hasNewLayout();
|
||||
|
@@ -58,7 +58,6 @@ public class CSSNodeDEPRECATED implements CSSNodeAPI<CSSNodeDEPRECATED> {
|
||||
private @Nullable CSSNodeDEPRECATED mParent;
|
||||
private @Nullable MeasureFunction mMeasureFunction = null;
|
||||
private LayoutState mLayoutState = LayoutState.DIRTY;
|
||||
private boolean mIsTextNode = false;
|
||||
private Object mData;
|
||||
|
||||
@Override
|
||||
@@ -124,16 +123,6 @@ public class CSSNodeDEPRECATED implements CSSNodeAPI<CSSNodeDEPRECATED> {
|
||||
return mMeasureFunction != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIsTextNode(boolean isTextNode) {
|
||||
mIsTextNode = isTextNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTextNode() {
|
||||
return mIsTextNode;
|
||||
}
|
||||
|
||||
long measure(float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) {
|
||||
if (!isMeasureDefined()) {
|
||||
throw new RuntimeException("Measure function isn't defined!");
|
||||
|
@@ -240,7 +240,6 @@ public class LayoutEngine {
|
||||
}
|
||||
|
||||
/*package*/ static boolean canUseCachedMeasurement(
|
||||
boolean isTextNode,
|
||||
float availableWidth,
|
||||
float availableHeight,
|
||||
float marginRow,
|
||||
@@ -281,38 +280,6 @@ public class LayoutEngine {
|
||||
return true;
|
||||
}
|
||||
|
||||
// We know this to be text so we can apply some more specialized heuristics.
|
||||
if (isTextNode) {
|
||||
if (isWidthSame) {
|
||||
if (heightMeasureMode == CSSMeasureMode.UNDEFINED) {
|
||||
// Width is the same and height is not restricted. Re-use cahced value.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (heightMeasureMode == CSSMeasureMode.AT_MOST &&
|
||||
cachedLayout.computedHeight < (availableHeight - marginColumn)) {
|
||||
// Width is the same and height restriction is greater than the cached height. Re-use cached value.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Width is the same but height restriction imposes smaller height than previously measured.
|
||||
// Update the cached value to respect the new height restriction.
|
||||
cachedLayout.computedHeight = availableHeight - marginColumn;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cachedLayout.widthMeasureMode == CSSMeasureMode.UNDEFINED) {
|
||||
if (widthMeasureMode == CSSMeasureMode.UNDEFINED ||
|
||||
(widthMeasureMode == CSSMeasureMode.AT_MOST &&
|
||||
cachedLayout.computedWidth <= (availableWidth - marginRow))) {
|
||||
// Previsouly this text was measured with no width restriction, if width is now restricted
|
||||
// but to a larger value than the previsouly measured width we can re-use the measurement
|
||||
// as we know it will fit.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -364,13 +331,13 @@ public class LayoutEngine {
|
||||
node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]);
|
||||
|
||||
// First, try to use the layout cache.
|
||||
if (canUseCachedMeasurement(node.isTextNode(), availableWidth, availableHeight, marginAxisRow, marginAxisColumn,
|
||||
if (canUseCachedMeasurement(availableWidth, availableHeight, marginAxisRow, marginAxisColumn,
|
||||
widthMeasureMode, heightMeasureMode, layout.cachedLayout)) {
|
||||
cachedResults = layout.cachedLayout;
|
||||
} else {
|
||||
// Try to use the measurement cache.
|
||||
for (int i = 0; i < layout.nextCachedMeasurementsIndex; i++) {
|
||||
if (canUseCachedMeasurement(node.isTextNode(), availableWidth, availableHeight, marginAxisRow, marginAxisColumn,
|
||||
if (canUseCachedMeasurement(availableWidth, availableHeight, marginAxisRow, marginAxisColumn,
|
||||
widthMeasureMode, heightMeasureMode, layout.cachedMeasurements[i])) {
|
||||
cachedResults = layout.cachedMeasurements[i];
|
||||
break;
|
||||
|
Reference in New Issue
Block a user