Skip to content

Commit 95550ec

Browse files
committed
optimize add method
1 parent 21806f2 commit 95550ec

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

sentry/src/main/java/io/sentry/featureflags/FeatureFlagBuffer.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,17 @@ public void add(final @Nullable String flag, final @Nullable Boolean result) {
4444
}
4545
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
4646
final int size = flags.size();
47-
final @NotNull ArrayList<FeatureFlagEntry> tmpList = new ArrayList<>(size + 1);
48-
for (FeatureFlagEntry entry : flags) {
49-
if (!entry.flag.equals(flag)) {
50-
tmpList.add(entry);
47+
for (int i = 0; i < size; i++) {
48+
if (flags.get(i).equals(flag)) {
49+
flags.remove(i);
50+
break;
5151
}
5252
}
53-
tmpList.add(new FeatureFlagEntry(flag, result, System.nanoTime()));
53+
flags.add(new FeatureFlagEntry(flag, result, System.nanoTime()));
5454

55-
if (tmpList.size() > maxSize) {
56-
tmpList.remove(0);
55+
if (flags.size() > maxSize) {
56+
flags.remove(0);
5757
}
58-
59-
flags = new CopyOnWriteArrayList<>(tmpList);
6058
}
6159
}
6260

0 commit comments

Comments
 (0)