From e40f2cb7e3db7f4f234ad695b2b572ddaf2dda04 Mon Sep 17 00:00:00 2001 From: AlexisDrogoul Date: Sat, 31 Jul 2021 16:36:40 +0700 Subject: [PATCH] Cuts release of ICollector instances from the pool when pooling is off --- msi.gama.core/src/msi/gama/util/Collector.java | 13 ++++++------- msi.gama.core/src/msi/gama/util/ICollector.java | 3 ++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/msi.gama.core/src/msi/gama/util/Collector.java b/msi.gama.core/src/msi/gama/util/Collector.java index 2f37df1964..54cfb04a69 100644 --- a/msi.gama.core/src/msi/gama/util/Collector.java +++ b/msi.gama.core/src/msi/gama/util/Collector.java @@ -36,15 +36,14 @@ public abstract class Collector> implements ICollector, Collection { - private static final PoolUtils.ObjectPool> LISTS = PoolUtils.create("Ordered Collectors", true, - () -> new Collector.AsList<>(), (from, to) -> to.set(from), c -> c.clear()); + private static final PoolUtils.ObjectPool> LISTS = + PoolUtils.create("Ordered Collectors", true, AsList::new, (from, to) -> to.set(from), ICollector::clear); - private static final PoolUtils.ObjectPool> SETS = PoolUtils.create("Unique Collectors", true, - () -> new Collector.AsSet<>(), (from, to) -> to.set(from), c -> c.clear()); + private static final PoolUtils.ObjectPool> SETS = + PoolUtils.create("Unique Collectors", true, AsSet::new, (from, to) -> to.set(from), ICollector::clear); - private static final PoolUtils.ObjectPool> ORDERED_SETS = - PoolUtils.create("Unique Ordered Collectors", true, () -> new Collector.AsOrderedSet<>(), - (from, to) -> to.set(from), c -> c.clear()); + private static final PoolUtils.ObjectPool> ORDERED_SETS = PoolUtils.create( + "Unique Ordered Collectors", true, AsOrderedSet::new, (from, to) -> to.set(from), ICollector::clear); @SuppressWarnings ("unchecked") public static final Collector.AsList getList() { diff --git a/msi.gama.core/src/msi/gama/util/ICollector.java b/msi.gama.core/src/msi/gama/util/ICollector.java index 7d6d3853bf..e11de9a01f 100644 --- a/msi.gama.core/src/msi/gama/util/ICollector.java +++ b/msi.gama.core/src/msi/gama/util/ICollector.java @@ -13,6 +13,7 @@ import java.io.Closeable; import java.util.Collection; +import msi.gama.common.util.PoolUtils; import msi.gama.common.util.RandomUtils; public interface ICollector extends Collection, Closeable { @@ -21,7 +22,7 @@ public interface ICollector extends Collection, Closeable { @Override default void close() { - Collector.release(this); + if (PoolUtils.POOL) { Collector.release(this); } } default void shuffleInPlaceWith(final RandomUtils random) {