java-topology/defects/libgdx/patch/libgdx-0006-after-action-delegate-o-n2.patch

25 lines
1.1 KiB
Diff

# UNDF: UNDF-2026-000000747
# UNDF:
--- a/gdx/src/com/badlogic/gdx/scenes/scene2d/actions/AfterAction.java
+++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/actions/AfterAction.java
@@ -38,12 +38,17 @@
protected boolean delegate (float delta) {
Array<Action> currentActions = target.getActions();
if (currentActions.size == 1) waitForActions.clear();
- for (int i = waitForActions.size - 1; i >= 0; i--) {
+ // CWE-407 fix: build an ObjectSet from currentActions once (O(A)) instead of
+ // calling indexOf() O(A) for each of the W waitForActions → was O(W*A) per frame.
+ ObjectSet<Action> currentSet = new ObjectSet<>(currentActions.size);
+ for (int i = 0, n = currentActions.size; i < n; i++)
+ currentSet.add(currentActions.get(i));
+ for (int i = waitForActions.size - 1; i >= 0; i--) {
Action action = waitForActions.get(i);
- int index = currentActions.indexOf(action, true);
- if (index == -1) waitForActions.removeIndex(i);
+ if (!currentSet.contains(action)) waitForActions.removeIndex(i);
}
if (waitForActions.size > 0) return false;
return action.act(delta);
}
@@ -1,3 +1,4 @@
+import com.badlogic.gdx.utils.ObjectSet;