Avoid foreach for sensitive code

This commit is contained in:
TheMode 2021-06-10 11:53:50 +02:00
parent 6ef40e08c7
commit 3b80335134
2 changed files with 13 additions and 11 deletions

View File

@ -150,9 +150,11 @@ public interface EventListener<T extends Event> {
} }
// Filtering // Filtering
if (!filters.isEmpty()) { if (!filters.isEmpty()) {
if (filters.stream().anyMatch(filter -> !filter.test(event))) { for (var filter : filters) {
// Cancelled if (!filter.test(event)) {
return Result.INVALID; // Cancelled
return Result.INVALID;
}
} }
} }
// Handler // Handler

View File

@ -327,12 +327,12 @@ public class EventNode<T extends Event> {
} }
synchronized (GLOBAL_CHILD_LOCK) { synchronized (GLOBAL_CHILD_LOCK) {
List<EventNode<E>> result = new ArrayList<>(); List<EventNode<E>> result = new ArrayList<>();
this.children.forEach(child -> { for (EventNode<T> child : children) {
if (EventNode.equals(child, name, eventType)) { if (EventNode.equals(child, name, eventType)) {
result.add((EventNode<E>) child); result.add((EventNode<E>) child);
} }
result.addAll(child.findChildren(name, eventType)); result.addAll(child.findChildren(name, eventType));
}); }
return result; return result;
} }
} }
@ -362,14 +362,14 @@ public class EventNode<T extends Event> {
return; return;
} }
synchronized (GLOBAL_CHILD_LOCK) { synchronized (GLOBAL_CHILD_LOCK) {
this.children.forEach(child -> { for (EventNode<T> child : children) {
if (EventNode.equals(child, name, eventType)) { if (EventNode.equals(child, name, eventType)) {
removeChild(child); removeChild(child);
addChild(eventNode); addChild(eventNode);
return; continue;
} }
child.replaceChildren(name, eventType, eventNode); child.replaceChildren(name, eventType, eventNode);
}); }
} }
} }
@ -396,13 +396,13 @@ public class EventNode<T extends Event> {
return; return;
} }
synchronized (GLOBAL_CHILD_LOCK) { synchronized (GLOBAL_CHILD_LOCK) {
this.children.forEach(child -> { for (EventNode<T> child : children) {
if (EventNode.equals(child, name, eventType)) { if (EventNode.equals(child, name, eventType)) {
removeChild(child); removeChild(child);
return; continue;
} }
child.removeChildren(name, eventType); child.removeChildren(name, eventType);
}); }
} }
} }