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
This commit is contained in:
Fabrizio Cucci
2024-04-03 02:43:36 -07:00
committed by Facebook GitHub Bot
parent 08af9eaa29
commit 669bcb8675
2 changed files with 20 additions and 33 deletions
@@ -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<YogaNode> sPool;
public static ClearableSynchronizedPool<YogaNode> get() {
if (sPool != null) {
return sPool;
}
synchronized (sInitLock) {
if (sPool == null) {
sPool = new ClearableSynchronizedPool<>(1024);
}
return sPool;
}
}
}
@@ -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<YogaNode> by
lazy(LazyThreadSafetyMode.SYNCHRONIZED) { ClearableSynchronizedPool(1024) }
@JvmStatic fun get(): ClearableSynchronizedPool<YogaNode> = pool
}