diff --git a/java/com/facebook/yoga/YogaNodeJNI.java b/java/com/facebook/yoga/YogaNodeJNI.java index 790b23bf..41e1a461 100644 --- a/java/com/facebook/yoga/YogaNodeJNI.java +++ b/java/com/facebook/yoga/YogaNodeJNI.java @@ -36,8 +36,6 @@ public class YogaNodeJNI extends YogaNode { private static final int PADDING = 2; private static final int BORDER = 4; - private final boolean mAvoidGlobalJNIRefs; - @DoNotStrip private float mWidth = YogaConstants.UNDEFINED; @DoNotStrip @@ -78,17 +76,15 @@ public class YogaNodeJNI extends YogaNode { private native long jni_YGNodeNew(); public YogaNodeJNI() { - mAvoidGlobalJNIRefs = false; mNativePointer = jni_YGNodeNew(); if (mNativePointer == 0) { throw new IllegalStateException("Failed to allocate native memory"); } } - private native long jni_YGNodeNewWithConfig(long configPointer, boolean avoidGlobalJNIRefs); + private native long jni_YGNodeNewWithConfig(long configPointer); public YogaNodeJNI(YogaConfig config) { - mAvoidGlobalJNIRefs = config.avoidGlobalJNIRefs; - mNativePointer = jni_YGNodeNewWithConfig(config.mNativePointer, mAvoidGlobalJNIRefs); + mNativePointer = jni_YGNodeNewWithConfig(config.mNativePointer); if (mNativePointer == 0) { throw new IllegalStateException("Failed to allocate native memory"); } @@ -231,21 +227,19 @@ public class YogaNodeJNI extends YogaNode { long[] nativePointers = null; YogaNodeJNI[] nodes = null; - if (mAvoidGlobalJNIRefs) { - ArrayList n = new ArrayList<>(); - n.add(this); - for (int i = 0; i < n.size(); ++i) { - List children = n.get(i).mChildren; - if (children != null) { - n.addAll(children); - } + ArrayList n = new ArrayList<>(); + n.add(this); + for (int i = 0; i < n.size(); ++i) { + List children = n.get(i).mChildren; + if (children != null) { + n.addAll(children); } + } - nodes = n.toArray(new YogaNodeJNI[n.size()]); - nativePointers = new long[nodes.length]; - for (int i = 0; i < nodes.length; ++i) { - nativePointers[i] = nodes[i].mNativePointer; - } + nodes = n.toArray(new YogaNodeJNI[n.size()]); + nativePointers = new long[nodes.length]; + for (int i = 0; i < nodes.length; ++i) { + nativePointers[i] = nodes[i].mNativePointer; } jni_YGNodeCalculateLayout(mNativePointer, width, height, nativePointers, nodes); diff --git a/java/jni/YGJNI.cpp b/java/jni/YGJNI.cpp index f1d9feaa..71f04c6f 100644 --- a/java/jni/YGJNI.cpp +++ b/java/jni/YGJNI.cpp @@ -89,11 +89,7 @@ public: }; struct YGNodeContext { - weak_ref* ygNodeJObjectRef{nullptr}; int edgeSetFlag = 0; - ~YGNodeContext() { - delete ygNodeJObjectRef; - } }; const int MARGIN = 1; @@ -107,13 +103,7 @@ static inline YGNodeContext* ygNodeRefToYGNodeContext(YGNodeRef node) { static inline local_ref YGNodeJobject( YGNodeRef node, void* layoutContext) { - if (layoutContext == nullptr) { - return (reinterpret_cast*>( - ygNodeRefToYGNodeContext(node)->ygNodeJObjectRef)) - ->lockLocal(); - } else { - return reinterpret_cast(layoutContext)->ref(node); - } + return reinterpret_cast(layoutContext)->ref(node); } static void YGTransferLayoutDirection( @@ -320,25 +310,20 @@ static int YGJNILogFunc( return result; } -YGNodeContext* createYGNodeContext(alias_ref thiz) { - YGNodeContext* ygNodeContext = new YGNodeContext(); - ygNodeContext->ygNodeJObjectRef = new weak_ref(make_weak(thiz)); - return ygNodeContext; +YGNodeContext* createYGNodeContext() { + return new YGNodeContext(); } -jlong jni_YGNodeNew(alias_ref thiz) { +jlong jni_YGNodeNew(alias_ref) { const YGNodeRef node = YGNodeNew(); - node->setContext(createYGNodeContext(thiz)); + node->setContext(createYGNodeContext()); node->setPrintFunc(YGPrint); return reinterpret_cast(node); } -jlong jni_YGNodeNewWithConfig( - alias_ref thiz, - jlong configPointer, - jboolean avoidGlobalJNIRefs) { +jlong jni_YGNodeNewWithConfig(alias_ref, jlong configPointer) { const YGNodeRef node = YGNodeNewWithConfig(_jlong2YGConfigRef(configPointer)); - node->setContext(createYGNodeContext(avoidGlobalJNIRefs ? nullptr : thiz)); + node->setContext(createYGNodeContext()); return reinterpret_cast(node); } @@ -817,7 +802,7 @@ static void YGNodeSetStyleInputs( } void jni_YGNodeSetStyleInputs( - alias_ref thiz, + alias_ref, jlong nativePointer, alias_ref styleInputs, jint size) {