From 669bcb8675bb37e62a6bad995a65133fb7b1f56a Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Wed, 3 Apr 2024 02:43:36 -0700 Subject: [PATCH] Kotlinify YogaNodePool (#43786) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43786 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Reviewed By: alanleedev Differential Revision: D55643838 fbshipit-source-id: 0138a9a9c328bea4838ab4f4c5a0db8a7436ebbe --- .../react/uimanager/YogaNodePool.java | 33 ------------------- .../facebook/react/uimanager/YogaNodePool.kt | 20 +++++++++++ 2 files changed, 20 insertions(+), 33 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/YogaNodePool.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/YogaNodePool.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/YogaNodePool.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/YogaNodePool.java deleted file mode 100644 index 1af237ec325..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/YogaNodePool.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.uimanager; - -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.react.common.ClearableSynchronizedPool; -import com.facebook.yoga.YogaNode; - -/** Static holder for a recycling pool of YogaNodes. */ -@Nullsafe(Nullsafe.Mode.LOCAL) -class YogaNodePool { - - private static final Object sInitLock = new Object(); - private static ClearableSynchronizedPool sPool; - - public static ClearableSynchronizedPool get() { - if (sPool != null) { - return sPool; - } - - synchronized (sInitLock) { - if (sPool == null) { - sPool = new ClearableSynchronizedPool<>(1024); - } - return sPool; - } - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/YogaNodePool.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/YogaNodePool.kt new file mode 100644 index 00000000000..d76399e8f83 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/YogaNodePool.kt @@ -0,0 +1,20 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.uimanager + +import com.facebook.react.common.ClearableSynchronizedPool +import com.facebook.yoga.YogaNode + +/** Static holder for a recycling pool of YogaNodes. */ +internal object YogaNodePool { + + private val pool: ClearableSynchronizedPool by + lazy(LazyThreadSafetyMode.SYNCHRONIZED) { ClearableSynchronizedPool(1024) } + + @JvmStatic fun get(): ClearableSynchronizedPool = pool +}