joshb1050 commented on code in PR #4972: URL: https://github.com/apache/activemq-artemis/pull/4972#discussion_r1636884171
########## artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/SimpleAddressManager.java: ########## @@ -160,15 +172,7 @@ public Collection<Binding> getMatchingBindings(final SimpleString address) throw @Override public Collection<Binding> getDirectBindings(final SimpleString address) throws Exception { SimpleString realAddress = CompositeAddress.extractAddressName(address); - Collection<Binding> bindings = new ArrayList<>(); - - nameMap.forEach((bindingUniqueName, bindingAddressPair) -> { - if (bindingAddressPair.getA().getAddress().equals(realAddress)) { - bindings.add(bindingAddressPair.getA()); - } - }); - - return bindings; + return new ArrayList<>(directBindingMap.getOrDefault(realAddress, Collections.emptyList())); Review Comment: It's a copy operation, and works efficiently internally (at least in JDK 17). We could do a null check instead and return a new list if null, but this has to be a defensive copy since the tests will otherwise fail. ``` public ArrayList(Collection<? extends E> c) { Object[] a = c.toArray(); if ((size = a.length) != 0) { if (c.getClass() == ArrayList.class) { elementData = a; } else { elementData = Arrays.copyOf(a, size, Object[].class); } } else { // replace with empty array. elementData = EMPTY_ELEMENTDATA; } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org For additional commands, e-mail: gitbox-h...@activemq.apache.org For further information, visit: https://activemq.apache.org/contact