mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Avoid allocating empty lists
Summary: Changelog: [Internal] Optimize Fabric memory allocations on Android Reviewed By: genkikondo Differential Revision: D36098912 fbshipit-source-id: 8d34a652db019865a8306bc070a08f5ddfef96bf
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b9bb30b1ad
commit
5de0f145ec
@@ -133,9 +133,7 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec
|
||||
|
||||
@UiThread
|
||||
void executeBatch(long maxBatchNumber, NativeAnimatedNodesManager nodesManager) {
|
||||
|
||||
List<UIThreadOperation> operations;
|
||||
|
||||
if (mSynchronizedAccess) {
|
||||
synchronized (this) {
|
||||
operations = drainQueueIntoList(maxBatchNumber);
|
||||
@@ -143,13 +141,19 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec
|
||||
} else {
|
||||
operations = drainQueueIntoList(maxBatchNumber);
|
||||
}
|
||||
for (UIThreadOperation operation : operations) {
|
||||
operation.execute(nodesManager);
|
||||
if (operations != null) {
|
||||
for (UIThreadOperation operation : operations) {
|
||||
operation.execute(nodesManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private List<UIThreadOperation> drainQueueIntoList(long maxBatchNumber) {
|
||||
private @Nullable List<UIThreadOperation> drainQueueIntoList(long maxBatchNumber) {
|
||||
if (mQueue.isEmpty() && mPeekedOperation == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<UIThreadOperation> operations = new ArrayList<>();
|
||||
while (true) {
|
||||
// Due to a race condition, we manually "carry-over" a polled item from previous batch
|
||||
|
||||
+5
-2
@@ -356,13 +356,16 @@ public class MountItemDispatcher {
|
||||
@Nullable
|
||||
private static <E extends MountItem> List<E> drainConcurrentItemQueue(
|
||||
ConcurrentLinkedQueue<E> queue) {
|
||||
if (queue.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
List<E> result = new ArrayList<>();
|
||||
while (!queue.isEmpty()) {
|
||||
do {
|
||||
E item = queue.poll();
|
||||
if (item != null) {
|
||||
result.add(item);
|
||||
}
|
||||
}
|
||||
} while (!queue.isEmpty());
|
||||
if (result.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user