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
if (!filters.isEmpty()) {
if (filters.stream().anyMatch(filter -> !filter.test(event))) {
// Cancelled
return Result.INVALID;
for (var filter : filters) {
if (!filter.test(event)) {
// Cancelled
return Result.INVALID;
}
}
}
// Handler

View File

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