diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index fb02f33c4eb0b5..1ddf3d0d0101be 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -1798,16 +1798,6 @@ public final class com/facebook/react/common/LifecycleState : java/lang/Enum { public static fun values ()[Lcom/facebook/react/common/LifecycleState; } -public class com/facebook/react/common/LongArray { - public fun add (J)V - public static fun createWithInitialCapacity (I)Lcom/facebook/react/common/LongArray; - public fun dropTail (I)V - public fun get (I)J - public fun isEmpty ()Z - public fun set (IJ)V - public fun size ()I -} - public class com/facebook/react/common/MapBuilder { public fun ()V public static fun builder ()Lcom/facebook/react/common/MapBuilder$Builder; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/LongArray.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/LongArray.java deleted file mode 100644 index 30e4321c964d5a..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/LongArray.java +++ /dev/null @@ -1,75 +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.common; - -import com.facebook.infer.annotation.Nullsafe; - -/** Object wrapping an auto-expanding long[]. Like an ArrayList but without the autoboxing. */ -@Nullsafe(Nullsafe.Mode.LOCAL) -public class LongArray { - - private static final double INNER_ARRAY_GROWTH_FACTOR = 1.8; - - private long[] mArray; - private int mLength; - - public static LongArray createWithInitialCapacity(int initialCapacity) { - return new LongArray(initialCapacity); - } - - private LongArray(int initialCapacity) { - mArray = new long[initialCapacity]; - mLength = 0; - } - - public void add(long value) { - growArrayIfNeeded(); - mArray[mLength++] = value; - } - - public long get(int index) { - if (index >= mLength) { - throw new IndexOutOfBoundsException("" + index + " >= " + mLength); - } - return mArray[index]; - } - - public void set(int index, long value) { - if (index >= mLength) { - throw new IndexOutOfBoundsException("" + index + " >= " + mLength); - } - mArray[index] = value; - } - - public int size() { - return mLength; - } - - public boolean isEmpty() { - return mLength == 0; - } - - /** Removes the *last* n items of the array all at once. */ - public void dropTail(int n) { - if (n > mLength) { - throw new IndexOutOfBoundsException( - "Trying to drop " + n + " items from array of length " + mLength); - } - mLength -= n; - } - - private void growArrayIfNeeded() { - if (mLength == mArray.length) { - // If the initial capacity was 1 we need to ensure it at least grows by 1. - int newSize = Math.max(mLength + 1, (int) (mLength * INNER_ARRAY_GROWTH_FACTOR)); - long[] newArray = new long[newSize]; - System.arraycopy(mArray, 0, newArray, 0, mLength); - mArray = newArray; - } - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DidJSUpdateUiDuringFrameDetector.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DidJSUpdateUiDuringFrameDetector.kt index 01424ae7d3bc76..b8dec0416df99a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DidJSUpdateUiDuringFrameDetector.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DidJSUpdateUiDuringFrameDetector.kt @@ -8,7 +8,6 @@ package com.facebook.react.modules.debug import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener -import com.facebook.react.common.LongArray import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugListener /** @@ -19,10 +18,10 @@ import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugL */ internal class DidJSUpdateUiDuringFrameDetector : NotThreadSafeBridgeIdleDebugListener, NotThreadSafeViewHierarchyUpdateDebugListener { - private val transitionToIdleEvents = LongArray.createWithInitialCapacity(20) - private val transitionToBusyEvents = LongArray.createWithInitialCapacity(20) - private val viewHierarchyUpdateEnqueuedEvents = LongArray.createWithInitialCapacity(20) - private val viewHierarchyUpdateFinishedEvents = LongArray.createWithInitialCapacity(20) + private val transitionToIdleEvents = ArrayList(20) + private val transitionToBusyEvents = ArrayList(20) + private val viewHierarchyUpdateEnqueuedEvents = ArrayList(20) + private val viewHierarchyUpdateFinishedEvents = ArrayList(20) @Volatile private var wasIdleAtEndOfLastFrame = true @Synchronized @@ -106,53 +105,42 @@ internal class DidJSUpdateUiDuringFrameDetector : wasIdleAtEndOfLastFrame } else lastIdleTransition > lastBusyTransition } +} - companion object { - private fun hasEventBetweenTimestamps( - eventArray: LongArray, - startTime: Long, - endTime: Long - ): Boolean { - for (i in 0 until eventArray.size()) { - val time = eventArray[i] - if (time in startTime until endTime) { - return true - } - } - return false - } +private fun hasEventBetweenTimestamps( + eventArray: ArrayList, + startTime: Long, + endTime: Long +): Boolean = eventArray.any { time -> time in startTime until endTime } - private fun getLastEventBetweenTimestamps( - eventArray: LongArray, - startTime: Long, - endTime: Long - ): Long { - var lastEvent: Long = -1 - for (i in 0 until eventArray.size()) { - val time = eventArray[i] - if (time in startTime until endTime) { - lastEvent = time - } else if (time >= endTime) { - break - } - } - return lastEvent +private fun getLastEventBetweenTimestamps( + eventArray: ArrayList, + startTime: Long, + endTime: Long +): Long { + var lastEvent: Long = -1 + for (time in eventArray) { + if (time in startTime until endTime) { + lastEvent = time + } else if (time >= endTime) { + break } + } + return lastEvent +} - private fun cleanUp(eventArray: LongArray, endTime: Long) { - val size = eventArray.size() - var indicesToRemove = 0 - for (i in 0 until size) { - if (eventArray[i] < endTime) { - indicesToRemove++ - } - } - if (indicesToRemove > 0) { - for (i in 0 until size - indicesToRemove) { - eventArray[i] = eventArray[i + indicesToRemove] - } - eventArray.dropTail(indicesToRemove) - } +private fun cleanUp(eventArray: ArrayList, endTime: Long) { + val size = eventArray.size + var indicesToRemove = 0 + for (i in 0 until size) { + if (eventArray[i] < endTime) { + indicesToRemove++ + } + } + if (indicesToRemove > 0) { + for (i in 0 until size - indicesToRemove) { + eventArray[i] = eventArray[i + indicesToRemove] } + eventArray.dropLast(indicesToRemove) } }