# HG changeset patch # User Alexander Simon # Date 1410849291 -14400 # Tue Sep 16 10:34:51 2014 +0400 # Node ID 907049d30401746f9b1c371271c13149ab16db8d # Parent fd6a6de7be2ba0857a3943400c470dbf1116ce2f fixed Bug #247146 Inefficient removing all nodes from Children.Array diff --git a/openide.nodes/src/org/openide/nodes/Children.java b/openide.nodes/src/org/openide/nodes/Children.java --- a/openide.nodes/src/org/openide/nodes/Children.java +++ b/openide.nodes/src/org/openide/nodes/Children.java @@ -832,9 +832,26 @@ @Override public boolean remove(final Node[] arr) { synchronized (COLLECTION_LOCK) { - if (!getCollection().removeAll(Arrays.asList(arr))) { - // the collection was not changed - return false; + final Collection collection = getCollection(); + // fast check + boolean same = false; + if (collection.size() == arr.length) { + same = true; + int i = 0; + for (Node n : collection) { + if (n != arr[i++]) { + same = false; + break; + } + } + } + if (same) { + collection.clear(); + } else { + if (!collection.removeAll(Arrays.asList(arr))) { + // the collection was not changed + return false; + } } } @@ -842,7 +859,7 @@ return true; } - + /** One entry that holds all the nodes in the collection * member called nodes. */