Skip to content

Commit

Permalink
Cuts release of ICollector instances from the pool when pooling is off
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Jul 31, 2021
1 parent 11ed4cb commit e40f2cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 6 additions & 7 deletions msi.gama.core/src/msi/gama/util/Collector.java
Expand Up @@ -36,15 +36,14 @@

public abstract class Collector<E, C extends Collection<E>> implements ICollector<E>, Collection<E> {

private static final PoolUtils.ObjectPool<ICollector<?>> LISTS = PoolUtils.create("Ordered Collectors", true,
() -> new Collector.AsList<>(), (from, to) -> to.set(from), c -> c.clear());
private static final PoolUtils.ObjectPool<ICollector<?>> LISTS =
PoolUtils.create("Ordered Collectors", true, AsList::new, (from, to) -> to.set(from), ICollector::clear);

private static final PoolUtils.ObjectPool<ICollector<?>> SETS = PoolUtils.create("Unique Collectors", true,
() -> new Collector.AsSet<>(), (from, to) -> to.set(from), c -> c.clear());
private static final PoolUtils.ObjectPool<ICollector<?>> SETS =
PoolUtils.create("Unique Collectors", true, AsSet::new, (from, to) -> to.set(from), ICollector::clear);

private static final PoolUtils.ObjectPool<ICollector<?>> ORDERED_SETS =
PoolUtils.create("Unique Ordered Collectors", true, () -> new Collector.AsOrderedSet<>(),
(from, to) -> to.set(from), c -> c.clear());
private static final PoolUtils.ObjectPool<ICollector<?>> ORDERED_SETS = PoolUtils.create(
"Unique Ordered Collectors", true, AsOrderedSet::new, (from, to) -> to.set(from), ICollector::clear);

@SuppressWarnings ("unchecked")
public static final <T> Collector.AsList<T> getList() {
Expand Down
3 changes: 2 additions & 1 deletion msi.gama.core/src/msi/gama/util/ICollector.java
Expand Up @@ -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<E> extends Collection<E>, Closeable {
Expand All @@ -21,7 +22,7 @@ public interface ICollector<E> extends Collection<E>, Closeable {

@Override
default void close() {
Collector.release(this);
if (PoolUtils.POOL) { Collector.release(this); }
}

default void shuffleInPlaceWith(final RandomUtils random) {
Expand Down

0 comments on commit e40f2cb

Please sign in to comment.