Reuse existing region objects on replace
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java
index c7e28e7..57b75da 100644
--- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java
+++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java
@@ -413,11 +413,23 @@
if (check && this.updateCount.get() != replacement.originUpdateCount) {
throw new BundleException("The origin update count has changed since the replacement copy was created.", BundleException.INVALID_OPERATION); //$NON-NLS-1$
}
+ Map<String, Region> nameToRegion = new HashMap<String, Region>();
+ for (Region region : regions) {
+ nameToRegion.put(region.getName(), region);
+ }
this.regions.clear();
this.edges.clear();
this.bundleIdToRegionMapping.clear();
for (Region original : filteredRegions.keySet()) {
- Region copy = this.createRegion(original.getName());
+ Region copy = nameToRegion.get(original.getName());
+ if (copy != null) {
+ // reuse the previous region object
+ regions.add(copy);
+ edges.put(copy, EMPTY_EDGE_SET);
+ } else {
+ // create a new one
+ copy = this.createRegion(original.getName());
+ }
for (Long id : original.getBundleIds()) {
copy.addBundle(id);
}