From c7ed3981ee719b21331caace4a504d8b89ff12bc Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Wed, 23 Oct 2019 02:35:21 -0700 Subject: [PATCH] Remove setStyleInputs API Summary: setStyleInputs batching API was added to reduce the number of jni calls and although it improved performance in yoga world but was not impactful in litho and is not used anywhere. Removing this saves around 500 bytes per architecture #Changelog: [Internal][Yoga] Removed unused code setStyleInputs batching API form Yoga Reviewed By: amir-shalem Differential Revision: D18036536 fbshipit-source-id: 7436b55dcd464dd9f9cc46406d4fd78d12babe55 --- .../main/java/com/facebook/yoga/YogaNode.java | 2 - .../com/facebook/yoga/YogaNodeJNIBase.java | 7 - .../jni/first-party/yogajni/jni/YGJNI.cpp | 11 - .../main/jni/first-party/yogajni/jni/YGJNI.h | 211 ------------------ .../first-party/yogajni/jni/YGJNIVanilla.cpp | 14 -- 5 files changed, 245 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java b/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java index 3b706815720..baa0c517b52 100644 --- a/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java +++ b/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java @@ -213,7 +213,5 @@ public abstract class YogaNode { public abstract void print(); - public abstract void setStyleInputs(float[] styleInputs, int size); - public abstract YogaNode cloneWithoutChildren(); } diff --git a/ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java b/ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java index 036e6114d4f..c08e43ded6d 100644 --- a/ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -678,13 +678,6 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { YogaNative.jni_YGNodePrint(mNativePointer); } - public void setStyleInputs(float[] styleInputsArray, int size) { - if (useVanillaJNI) - YogaNative.jni_YGNodeSetStyleInputsJNI(mNativePointer, styleInputsArray, size); - else - YogaNative.jni_YGNodeSetStyleInputs(mNativePointer, styleInputsArray, size); - } - /** * This method replaces the child at childIndex position with the newNode received by parameter. * This is different than calling removeChildAt and addChildAt because this method ONLY replaces diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp index a377f17ad5f..8691b8bfe2d 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp @@ -531,16 +531,6 @@ void jni_YGConfigSetLogger( } } -void jni_YGNodeSetStyleInputs( - alias_ref, - jlong nativePointer, - alias_ref styleInputs, - jint size) { - float result[size]; - styleInputs->getRegion(0, size, result); - YGNodeSetStyleInputs(_jlong2YGNodeRef(nativePointer), result, size); -} - jlong jni_YGNodeStyleGetMargin(jlong nativePointer, jint edge) { YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer); if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::MARGIN)) { @@ -706,7 +696,6 @@ jint YGJNI::registerNativeMethods(JavaVM* vm) { YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAspectRatio), YGMakeCriticalNativeMethod(jni_YGNodePrint), YGMakeNativeMethod(jni_YGNodeClone), - YGMakeNativeMethod(jni_YGNodeSetStyleInputs), YGMakeNativeMethod(jni_YGConfigNew), YGMakeNativeMethod(jni_YGConfigFree), YGMakeNativeMethod(jni_YGConfigSetExperimentalFeatureEnabled), diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h index 7bafdd52fd3..dbff73f9eb4 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h @@ -5,49 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -enum YGStyleInput { - LayoutDirection, - FlexDirection, - Flex, - FlexGrow, - FlexShrink, - FlexBasis, - FlexBasisPercent, - FlexBasisAuto, - FlexWrap, - Width, - WidthPercent, - WidthAuto, - MinWidth, - MinWidthPercent, - MaxWidth, - MaxWidthPercent, - Height, - HeightPercent, - HeightAuto, - MinHeight, - MinHeightPercent, - MaxHeight, - MaxHeightPercent, - JustifyContent, - AlignItems, - AlignSelf, - AlignContent, - PositionType, - AspectRatio, - Overflow, - Display, - Margin, - MarginPercent, - MarginAuto, - Padding, - PaddingPercent, - Border, - Position, - PositionPercent, - IsReferenceBaseline, -}; - const short int LAYOUT_EDGE_SET_FLAG_INDEX = 0; const short int LAYOUT_WIDTH_INDEX = 1; const short int LAYOUT_HEIGHT_INDEX = 2; @@ -113,171 +70,3 @@ struct YogaValue { } }; } // namespace - -static void YGNodeSetStyleInputs( - const YGNodeRef node, - float* styleInputs, - int size) { - const auto end = styleInputs + size; - auto edgesSet = YGNodeEdges{node}; - while (styleInputs < end) { - auto styleInputKey = static_cast((int) *styleInputs++); - switch (styleInputKey) { - case LayoutDirection: - YGNodeStyleSetDirection(node, static_cast(*styleInputs++)); - break; - case FlexDirection: - YGNodeStyleSetFlexDirection( - node, static_cast(*styleInputs++)); - break; - case Flex: - YGNodeStyleSetFlex(node, *styleInputs++); - break; - case FlexGrow: - YGNodeStyleSetFlexGrow(node, *styleInputs++); - break; - case FlexShrink: - YGNodeStyleSetFlexShrink(node, *styleInputs++); - break; - case FlexBasis: - YGNodeStyleSetFlexBasis(node, *styleInputs++); - break; - case FlexBasisPercent: - YGNodeStyleSetFlexBasisPercent(node, *styleInputs++); - break; - case FlexBasisAuto: - YGNodeStyleSetFlexBasisAuto(node); - break; - case FlexWrap: - YGNodeStyleSetFlexWrap(node, static_cast(*styleInputs++)); - break; - case Width: - YGNodeStyleSetWidth(node, *styleInputs++); - break; - case WidthPercent: - YGNodeStyleSetWidthPercent(node, *styleInputs++); - break; - case WidthAuto: - YGNodeStyleSetWidthAuto(node); - break; - case MinWidth: - YGNodeStyleSetMinWidth(node, *styleInputs++); - break; - case MinWidthPercent: - YGNodeStyleSetMinWidthPercent(node, *styleInputs++); - break; - case MaxWidth: - YGNodeStyleSetMaxWidth(node, *styleInputs++); - break; - case MaxWidthPercent: - YGNodeStyleSetMaxWidthPercent(node, *styleInputs++); - break; - case Height: - YGNodeStyleSetHeight(node, *styleInputs++); - break; - case HeightPercent: - YGNodeStyleSetHeightPercent(node, *styleInputs++); - break; - case HeightAuto: - YGNodeStyleSetHeightAuto(node); - break; - case MinHeight: - YGNodeStyleSetMinHeight(node, *styleInputs++); - break; - case MinHeightPercent: - YGNodeStyleSetMinHeightPercent(node, *styleInputs++); - break; - case MaxHeight: - YGNodeStyleSetMaxHeight(node, *styleInputs++); - break; - case MaxHeightPercent: - YGNodeStyleSetMaxHeightPercent(node, *styleInputs++); - break; - case JustifyContent: - YGNodeStyleSetJustifyContent( - node, static_cast(*styleInputs++)); - break; - case AlignItems: - YGNodeStyleSetAlignItems(node, static_cast(*styleInputs++)); - break; - case AlignSelf: - YGNodeStyleSetAlignSelf(node, static_cast(*styleInputs++)); - break; - case AlignContent: - YGNodeStyleSetAlignContent(node, static_cast(*styleInputs++)); - break; - case PositionType: - YGNodeStyleSetPositionType( - node, static_cast(*styleInputs++)); - break; - case AspectRatio: - YGNodeStyleSetAspectRatio(node, *styleInputs++); - break; - case Overflow: - YGNodeStyleSetOverflow(node, static_cast(*styleInputs++)); - break; - case Display: - YGNodeStyleSetDisplay(node, static_cast(*styleInputs++)); - break; - case Margin: { - auto edge = static_cast(*styleInputs++); - float marginValue = *styleInputs++; - edgesSet.add(YGNodeEdges::MARGIN); - YGNodeStyleSetMargin(node, edge, marginValue); - break; - } - case MarginPercent: { - auto edge = static_cast(*styleInputs++); - float marginPercent = *styleInputs++; - edgesSet.add(YGNodeEdges::MARGIN); - YGNodeStyleSetMarginPercent(node, edge, marginPercent); - break; - } - case MarginAuto: { - edgesSet.add(YGNodeEdges::MARGIN); - YGNodeStyleSetMarginAuto(node, static_cast(*styleInputs++)); - break; - } - case Padding: { - auto edge = static_cast(*styleInputs++); - float paddingValue = *styleInputs++; - edgesSet.add(YGNodeEdges::PADDING); - YGNodeStyleSetPadding(node, edge, paddingValue); - break; - } - case PaddingPercent: { - auto edge = static_cast(*styleInputs++); - float paddingPercent = *styleInputs++; - edgesSet.add(YGNodeEdges::PADDING); - YGNodeStyleSetPaddingPercent(node, edge, paddingPercent); - break; - } - case Border: { - auto edge = static_cast(*styleInputs++); - float borderValue = *styleInputs++; - edgesSet.add(YGNodeEdges::BORDER); - YGNodeStyleSetBorder(node, edge, borderValue); - break; - } - case Position: { - auto edge = static_cast(*styleInputs++); - float positionValue = *styleInputs++; - YGNodeStyleSetPosition(node, edge, positionValue); - break; - } - case PositionPercent: { - auto edge = static_cast(*styleInputs++); - float positionPercent = *styleInputs++; - YGNodeStyleSetPositionPercent(node, edge, positionPercent); - break; - } - case IsReferenceBaseline: { - YGNodeSetIsReferenceBaseline(node, *styleInputs++ == 1 ? true : false); - break; - } - default: - break; - } - } - edgesSet.setOn(node); -} diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.cpp b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.cpp index 9a38c5755c0..3ac88ac1bfe 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.cpp +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.cpp @@ -721,17 +721,6 @@ static jlong jni_YGNodeCloneJNI(JNIEnv* env, jobject obj, jlong nativePointer) { // Yoga specific properties, not compatible with flexbox specification YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio); -static void jni_YGNodeSetStyleInputsJNI( - JNIEnv* env, - jobject obj, - jlong nativePointer, - jfloatArray styleInputs, - jint size) { - float result[size]; - env->GetFloatArrayRegion(styleInputs, 0, size, result); - YGNodeSetStyleInputs(_jlong2YGNodeRef(nativePointer), result, size); -} - static JNINativeMethod methods[] = { {"jni_YGConfigNewJNI", "()J", (void*) jni_YGConfigNewJNI}, {"jni_YGConfigFreeJNI", "(J)V", (void*) jni_YGConfigFreeJNI}, @@ -969,9 +958,6 @@ static JNINativeMethod methods[] = { "(JZ)V", (void*) jni_YGNodeSetHasBaselineFuncJNI}, {"jni_YGNodePrintJNI", "(J)V", (void*) jni_YGNodePrintJNI}, - {"jni_YGNodeSetStyleInputsJNI", - "(J[FI)V", - (void*) jni_YGNodeSetStyleInputsJNI}, {"jni_YGNodeCloneJNI", "(J)J", (void*) jni_YGNodeCloneJNI}, };