diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index e88b07f16..9f3486a10 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -2635,17 +2635,11 @@ public class PApplet implements PConstants { keyPressed = true; keyPressed(keyEvent); } - case KeyEvent.RELEASE -> { - List hashesToRemove = new ArrayList<>(); - for (Long hash : pressedKeys) { - int storedKeyCode = (int)(hash >> Character.SIZE); - if (storedKeyCode == keyCode) { - hashesToRemove.add(hash); - } - } - - pressedKeys.removeAll(hashesToRemove); - + case KeyEvent.RELEASE -> { + pressedKeys.removeIf(hash -> { + int pressedKeyCode = (int)(hash >> Character.SIZE); + return pressedKeyCode == keyCode; + }); keyPressed = !pressedKeys.isEmpty(); keyReleased(keyEvent); } diff --git a/core/test/processing/core/PAppletKeyEventTest.java b/core/test/processing/core/PAppletKeyEventTest.java index f40511ec5..19770ebc3 100644 --- a/core/test/processing/core/PAppletKeyEventTest.java +++ b/core/test/processing/core/PAppletKeyEventTest.java @@ -45,7 +45,7 @@ public class PAppletKeyEventTest { applet.handleKeyEvent(releaseShift); Assert.assertFalse("keyPressed should be false after all keys released", applet.keyPressed); - Assert.assertEquals("pressedKeys should be empty", true, applet.pressedKeys.isEmpty()); + Assert.assertTrue("pressedKeys should be empty", applet.pressedKeys.isEmpty()); } @Test @@ -81,7 +81,7 @@ public class PAppletKeyEventTest { applet.handleKeyEvent(releaseAlt); Assert.assertFalse("keyPressed should be false after all keys released", applet.keyPressed); - Assert.assertEquals("pressedKeys should be empty", true, applet.pressedKeys.isEmpty()); + Assert.assertTrue("pressedKeys should be empty", applet.pressedKeys.isEmpty()); } @Test