From af47f1a8259ae76b19addc7cde9e05e55c7b0bcb Mon Sep 17 00:00:00 2001 From: Vaci Koblizek Date: Thu, 12 Nov 2020 20:40:18 +0000 Subject: [PATCH] simplify iteration of (weak) question table --- .../src/main/java/org/capnproto/RpcState.java | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/runtime-rpc/src/main/java/org/capnproto/RpcState.java b/runtime-rpc/src/main/java/org/capnproto/RpcState.java index 68d7a1b..c364b34 100644 --- a/runtime-rpc/src/main/java/org/capnproto/RpcState.java +++ b/runtime-rpc/src/main/java/org/capnproto/RpcState.java @@ -117,7 +117,7 @@ final class RpcState { } } - class QuestionExportTable implements Iterable { + class QuestionExportTable { private final HashMap> slots = new HashMap<>(); private final Queue freeIds = new PriorityQueue<>(); private int max = 0; @@ -146,20 +146,12 @@ final class RpcState { return value; } - @Override - public Iterator iterator() { - return this.slots.values() - .stream() - .map(Reference::get) - .filter(Objects::nonNull) - .iterator(); - } - - @Override public void forEach(Consumer action) { - var iter = this.iterator(); - while (iter.hasNext()) { - action.accept(iter.next()); + for (var entry: this.slots.values()) { + var question = entry.get(); + if (question != null) { + action.accept(question); + } } } } @@ -297,9 +289,7 @@ final class RpcState { var networkExc = RpcException.disconnected(exc.getMessage()); // All current questions complete with exceptions. - for (var question: questions) { - question.reject(networkExc); - } + questions.forEach(question -> question.reject(networkExc)); List pipelinesToRelease = new ArrayList<>(); List clientsToRelease = new ArrayList<>();