Bug 526010 - Very long check when deleting thousands of sub-packages

When deleting a package with a few thousand sub-packages, a check during
removal takes up to several minutes. This cannot be cancelled by
canceling the delete operation.

This check is done in DeleteModifications.postProcess. The method
iterates over all packages that are to be removed. For each of those
packages, the method will retrieve all sub-packages. For each of those
sub-packages, it checks whether that sub-package is to be removed. This
last check is on an array container. In total, this results in cubic
complexity.

With this change the algorithm which checks whether it can remove a
package completely has linear complexity, instead of quadratic. The
total complexity for deleting the packages is therefore quadratic,
instead of cubic. The check for a few thousand sub-packages then takes a
few seconds instead of minutes.

Change-Id: I097d58bdeaa650f06b38a1ee7bf38bdbc5a21127
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/reorg/DeleteModifications.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/reorg/DeleteModifications.java
index 84175e8..e3647f3 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/reorg/DeleteModifications.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/reorg/DeleteModifications.java
@@ -13,7 +13,9 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
+import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.eclipse.core.runtime.CoreException;
 
@@ -53,11 +55,11 @@
 	 * <code>handlePackageFragmentDelete</code>. This is part of the
 	 * algorithm to check if a parent folder can be deleted.
 	 */
-	private List<IPackageFragment> fPackagesToDelete;
+	private Set<IPackageFragment> fPackagesToDelete;
 
 	public DeleteModifications() {
 		fDelete= new ArrayList<>();
-		fPackagesToDelete= new ArrayList<>();
+		fPackagesToDelete= new LinkedHashSet<>();
 	}
 
 	public void delete(IResource resource) {