|
1 | 1 | package com.oblador.performance;
|
2 | 2 |
|
3 |
| -import android.os.Build; |
4 |
| - |
5 | 3 | import androidx.annotation.NonNull;
|
6 | 4 |
|
7 | 5 | import com.facebook.react.bridge.Arguments;
|
|
14 | 12 | import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
15 | 13 |
|
16 | 14 | import java.util.ArrayList;
|
| 15 | +import java.util.Iterator; |
17 | 16 | import java.util.List;
|
| 17 | +import java.util.Queue; |
| 18 | +import java.util.concurrent.ConcurrentLinkedQueue; |
18 | 19 |
|
19 | 20 | // Should extend NativeRNPerformanceManagerSpec when codegen for old architecture is solved
|
20 | 21 | public class PerformanceModule extends ReactContextBaseJavaModule implements TurboModule, RNPerformance.MarkerListener {
|
21 | 22 | public static final String PERFORMANCE_MODULE = "RNPerformanceManager";
|
22 | 23 | public static final String BRIDGE_SETUP_START = "bridgeSetupStart";
|
23 | 24 |
|
24 | 25 | private static boolean eventsBuffered = true;
|
25 |
| - private static final List<PerformanceEntry> markBuffer = new ArrayList<>(); |
| 26 | + private static final Queue<PerformanceEntry> markBuffer = new ConcurrentLinkedQueue<>(); |
26 | 27 | private static boolean didEmit = false;
|
27 | 28 |
|
28 | 29 | public PerformanceModule(@NonNull final ReactApplicationContext reactContext) {
|
@@ -88,13 +89,11 @@ public static void setupListener() {
|
88 | 89 | private static void clearMarkBuffer() {
|
89 | 90 | RNPerformance.getInstance().clearEphermalEntries();
|
90 | 91 |
|
91 |
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
92 |
| - markBuffer.removeIf(PerformanceEntry::isEphemeral); |
93 |
| - } else { |
94 |
| - for (PerformanceEntry entry : markBuffer) { |
95 |
| - if (entry.isEphemeral()) { |
96 |
| - markBuffer.remove(entry); |
97 |
| - } |
| 92 | + Iterator<PerformanceEntry> iterator = markBuffer.iterator(); |
| 93 | + while (iterator.hasNext()) { |
| 94 | + PerformanceEntry entry = iterator.next(); |
| 95 | + if (entry.isEphemeral()) { |
| 96 | + iterator.remove(); |
98 | 97 | }
|
99 | 98 | }
|
100 | 99 | }
|
@@ -156,14 +155,18 @@ private static void addMark(PerformanceEntry entry) {
|
156 | 155 |
|
157 | 156 | private void emitBufferedMarks() {
|
158 | 157 | didEmit = true;
|
159 |
| - for (PerformanceEntry entry : markBuffer) { |
| 158 | + Iterator<PerformanceEntry> iterator = markBuffer.iterator(); |
| 159 | + while (iterator.hasNext()) { |
| 160 | + PerformanceEntry entry = iterator.next(); |
160 | 161 | emitMark(entry);
|
161 | 162 | }
|
162 | 163 | emitNativeBufferedMarks();
|
163 | 164 | }
|
164 | 165 |
|
165 | 166 | private void emitNativeBufferedMarks() {
|
166 |
| - for (PerformanceEntry entry : RNPerformance.getInstance().getEntries()) { |
| 167 | + Iterator<PerformanceEntry> iterator = RNPerformance.getInstance().getEntries().iterator(); |
| 168 | + while (iterator.hasNext()) { |
| 169 | + PerformanceEntry entry = iterator.next(); |
167 | 170 | emitMark(entry);
|
168 | 171 | }
|
169 | 172 | }
|
|
0 commit comments