Use fromInt() instead of indexing values() as it allocates a new array

Summary: values() create a shallow copy of the underlying array every time as there are no immutable arrays in java. By using fromInt() we avoid this allocation.

Reviewed By: pasqualeanatriello

Differential Revision: D4494371

fbshipit-source-id: 11cff65114803e185bc67a96da0bf2a2c4a3e6d9
This commit is contained in:
Emil Sjolander
2017-02-02 15:27:41 -08:00
committed by Facebook Github Bot
parent 30413265c7
commit d62ca8c518

View File

@@ -211,7 +211,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native int jni_YGNodeStyleGetDirection(long nativePointer); private native int jni_YGNodeStyleGetDirection(long nativePointer);
@Override @Override
public YogaDirection getStyleDirection() { public YogaDirection getStyleDirection() {
return YogaDirection.values()[jni_YGNodeStyleGetDirection(mNativePointer)]; return YogaDirection.fromInt(jni_YGNodeStyleGetDirection(mNativePointer));
} }
private native void jni_YGNodeStyleSetDirection(long nativePointer, int direction); private native void jni_YGNodeStyleSetDirection(long nativePointer, int direction);
@@ -223,7 +223,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native int jni_YGNodeStyleGetFlexDirection(long nativePointer); private native int jni_YGNodeStyleGetFlexDirection(long nativePointer);
@Override @Override
public YogaFlexDirection getFlexDirection() { public YogaFlexDirection getFlexDirection() {
return YogaFlexDirection.values()[jni_YGNodeStyleGetFlexDirection(mNativePointer)]; return YogaFlexDirection.fromInt(jni_YGNodeStyleGetFlexDirection(mNativePointer));
} }
private native void jni_YGNodeStyleSetFlexDirection(long nativePointer, int flexDirection); private native void jni_YGNodeStyleSetFlexDirection(long nativePointer, int flexDirection);
@@ -235,7 +235,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native int jni_YGNodeStyleGetJustifyContent(long nativePointer); private native int jni_YGNodeStyleGetJustifyContent(long nativePointer);
@Override @Override
public YogaJustify getJustifyContent() { public YogaJustify getJustifyContent() {
return YogaJustify.values()[jni_YGNodeStyleGetJustifyContent(mNativePointer)]; return YogaJustify.fromInt(jni_YGNodeStyleGetJustifyContent(mNativePointer));
} }
private native void jni_YGNodeStyleSetJustifyContent(long nativePointer, int justifyContent); private native void jni_YGNodeStyleSetJustifyContent(long nativePointer, int justifyContent);
@@ -247,7 +247,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native int jni_YGNodeStyleGetAlignItems(long nativePointer); private native int jni_YGNodeStyleGetAlignItems(long nativePointer);
@Override @Override
public YogaAlign getAlignItems() { public YogaAlign getAlignItems() {
return YogaAlign.values()[jni_YGNodeStyleGetAlignItems(mNativePointer)]; return YogaAlign.fromInt(jni_YGNodeStyleGetAlignItems(mNativePointer));
} }
private native void jni_YGNodeStyleSetAlignItems(long nativePointer, int alignItems); private native void jni_YGNodeStyleSetAlignItems(long nativePointer, int alignItems);
@@ -259,7 +259,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native int jni_YGNodeStyleGetAlignSelf(long nativePointer); private native int jni_YGNodeStyleGetAlignSelf(long nativePointer);
@Override @Override
public YogaAlign getAlignSelf() { public YogaAlign getAlignSelf() {
return YogaAlign.values()[jni_YGNodeStyleGetAlignSelf(mNativePointer)]; return YogaAlign.fromInt(jni_YGNodeStyleGetAlignSelf(mNativePointer));
} }
private native void jni_YGNodeStyleSetAlignSelf(long nativePointer, int alignSelf); private native void jni_YGNodeStyleSetAlignSelf(long nativePointer, int alignSelf);
@@ -271,7 +271,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native int jni_YGNodeStyleGetAlignContent(long nativePointer); private native int jni_YGNodeStyleGetAlignContent(long nativePointer);
@Override @Override
public YogaAlign getAlignContent() { public YogaAlign getAlignContent() {
return YogaAlign.values()[jni_YGNodeStyleGetAlignContent(mNativePointer)]; return YogaAlign.fromInt(jni_YGNodeStyleGetAlignContent(mNativePointer));
} }
private native void jni_YGNodeStyleSetAlignContent(long nativePointer, int alignContent); private native void jni_YGNodeStyleSetAlignContent(long nativePointer, int alignContent);
@@ -283,7 +283,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native int jni_YGNodeStyleGetPositionType(long nativePointer); private native int jni_YGNodeStyleGetPositionType(long nativePointer);
@Override @Override
public YogaPositionType getPositionType() { public YogaPositionType getPositionType() {
return YogaPositionType.values()[jni_YGNodeStyleGetPositionType(mNativePointer)]; return YogaPositionType.fromInt(jni_YGNodeStyleGetPositionType(mNativePointer));
} }
private native void jni_YGNodeStyleSetPositionType(long nativePointer, int positionType); private native void jni_YGNodeStyleSetPositionType(long nativePointer, int positionType);
@@ -301,7 +301,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native int jni_YGNodeStyleGetOverflow(long nativePointer); private native int jni_YGNodeStyleGetOverflow(long nativePointer);
@Override @Override
public YogaOverflow getOverflow() { public YogaOverflow getOverflow() {
return YogaOverflow.values()[jni_YGNodeStyleGetOverflow(mNativePointer)]; return YogaOverflow.fromInt(jni_YGNodeStyleGetOverflow(mNativePointer));
} }
private native void jni_YGNodeStyleSetOverflow(long nativePointer, int overflow); private native void jni_YGNodeStyleSetOverflow(long nativePointer, int overflow);
@@ -623,7 +623,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
@Override @Override
public YogaDirection getLayoutDirection() { public YogaDirection getLayoutDirection() {
return YogaDirection.values()[mLayoutDirection]; return YogaDirection.fromInt(mLayoutDirection);
} }
private native void jni_YGNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc); private native void jni_YGNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc);
@@ -647,9 +647,9 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
return mMeasureFunction.measure( return mMeasureFunction.measure(
this, this,
width, width,
YogaMeasureMode.values()[widthMode], YogaMeasureMode.fromInt(widthMode),
height, height,
YogaMeasureMode.values()[heightMode]); YogaMeasureMode.fromInt(heightMode));
} }
private native void jni_YGNodeSetHasBaselineFunc(long nativePointer, boolean hasMeasureFunc); private native void jni_YGNodeSetHasBaselineFunc(long nativePointer, boolean hasMeasureFunc);