Create YogaValue
instances in Java, not C++
Summary: @public Passing primitive data via JNI is more efficient than passing objects. Here, we avoid creating `YogaValue` (Java) instances via JNI, and rather pass a `long` back to Java. The instance is then created by extracting the necessary bytes on the Java side. Reviewed By: foghina Differential Revision: D14576755 fbshipit-source-id: 22d09ad50c3ac6c49b0a797a0dad639ea4829df9
This commit is contained in:
committed by
Facebook Github Bot
parent
5bb2265083
commit
ca46c67e9e
@@ -349,7 +349,7 @@ public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
}
|
||||
|
||||
public YogaValue getFlexBasis() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetFlexBasis(mNativePointer);
|
||||
return valueFromLong(YogaNative.jni_YGNodeStyleGetFlexBasis(mNativePointer));
|
||||
}
|
||||
|
||||
public void setFlexBasis(float flexBasis) {
|
||||
@@ -365,7 +365,7 @@ public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
}
|
||||
|
||||
public YogaValue getMargin(YogaEdge edge) {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue());
|
||||
return valueFromLong(YogaNative.jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue()));
|
||||
}
|
||||
|
||||
public void setMargin(YogaEdge edge, float margin) {
|
||||
@@ -381,7 +381,7 @@ public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
}
|
||||
|
||||
public YogaValue getPadding(YogaEdge edge) {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue());
|
||||
return valueFromLong(YogaNative.jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue()));
|
||||
}
|
||||
|
||||
public void setPadding(YogaEdge edge, float padding) {
|
||||
@@ -401,7 +401,7 @@ public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
}
|
||||
|
||||
public YogaValue getPosition(YogaEdge edge) {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue());
|
||||
return valueFromLong(YogaNative.jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue()));
|
||||
}
|
||||
|
||||
public void setPosition(YogaEdge edge, float position) {
|
||||
@@ -413,7 +413,7 @@ public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
}
|
||||
|
||||
public YogaValue getWidth() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetWidth(mNativePointer);
|
||||
return valueFromLong(YogaNative.jni_YGNodeStyleGetWidth(mNativePointer));
|
||||
}
|
||||
|
||||
public void setWidth(float width) {
|
||||
@@ -429,7 +429,7 @@ public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
}
|
||||
|
||||
public YogaValue getHeight() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetHeight(mNativePointer);
|
||||
return valueFromLong(YogaNative.jni_YGNodeStyleGetHeight(mNativePointer));
|
||||
}
|
||||
|
||||
public void setHeight(float height) {
|
||||
@@ -445,7 +445,7 @@ public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
}
|
||||
|
||||
public YogaValue getMinWidth() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMinWidth(mNativePointer);
|
||||
return valueFromLong(YogaNative.jni_YGNodeStyleGetMinWidth(mNativePointer));
|
||||
}
|
||||
|
||||
public void setMinWidth(float minWidth) {
|
||||
@@ -457,7 +457,7 @@ public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
}
|
||||
|
||||
public YogaValue getMinHeight() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMinHeight(mNativePointer);
|
||||
return valueFromLong(YogaNative.jni_YGNodeStyleGetMinHeight(mNativePointer));
|
||||
}
|
||||
|
||||
public void setMinHeight(float minHeight) {
|
||||
@@ -469,7 +469,7 @@ public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
}
|
||||
|
||||
public YogaValue getMaxWidth() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMaxWidth(mNativePointer);
|
||||
return valueFromLong(YogaNative.jni_YGNodeStyleGetMaxWidth(mNativePointer));
|
||||
}
|
||||
|
||||
public void setMaxWidth(float maxWidth) {
|
||||
@@ -481,7 +481,7 @@ public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
}
|
||||
|
||||
public YogaValue getMaxHeight() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMaxHeight(mNativePointer);
|
||||
return valueFromLong(YogaNative.jni_YGNodeStyleGetMaxHeight(mNativePointer));
|
||||
}
|
||||
|
||||
public void setMaxHeight(float maxheight) {
|
||||
@@ -656,4 +656,8 @@ public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
newNode.mOwner = this;
|
||||
return newNode.mNativePointer;
|
||||
}
|
||||
|
||||
private static YogaValue valueFromLong(long raw) {
|
||||
return new YogaValue(Float.intBitsToFloat((int) raw), (int) (raw >> 32));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user