Skip to content

Commit

Permalink
Remove constructor with preFill argument from Pool (#6117)
Browse files Browse the repository at this point in the history
* Remove constructor with preFill argument from Pool

* CHANGES
  • Loading branch information
obigu committed Jul 24, 2020
1 parent 8937bde commit c3f77fd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 34 deletions.
3 changes: 3 additions & 0 deletions CHANGES
@@ -1,3 +1,6 @@
[1.9.12]
- API Change: Removed Pool constructor with preFill parameter in favor of using Pool#fill() method. See #6117

[1.9.11]
- Update to MobiVM 2.3.8
- Update to LWJGL 3.2.3
Expand Down
5 changes: 0 additions & 5 deletions gdx/src/com/badlogic/gdx/graphics/g2d/ParticleEffectPool.java
Expand Up @@ -28,11 +28,6 @@ public ParticleEffectPool (ParticleEffect effect, int initialCapacity, int max)
this.effect = effect;
}

public ParticleEffectPool (ParticleEffect effect, int initialCapacity, int max, boolean preFill) {
super(initialCapacity, max, preFill);
this.effect = effect;
}

protected PooledEffect newObject () {
PooledEffect pooledEffect = new PooledEffect(effect);
pooledEffect.start();
Expand Down
4 changes: 0 additions & 4 deletions gdx/src/com/badlogic/gdx/utils/FlushablePool.java
Expand Up @@ -34,10 +34,6 @@ public FlushablePool (int initialCapacity, int max) {
super(initialCapacity, max);
}

public FlushablePool (int initialCapacity, int max, boolean preFill) {
super(initialCapacity, max, preFill);
}

@Override
public T obtain () {
T result = super.obtain();
Expand Down
23 changes: 5 additions & 18 deletions gdx/src/com/badlogic/gdx/utils/Pool.java
Expand Up @@ -29,33 +29,20 @@ abstract public class Pool<T> {

/** Creates a pool with an initial capacity of 16 and no maximum. */
public Pool () {
this(16, Integer.MAX_VALUE, false);
this(16, Integer.MAX_VALUE);
}

/** Creates a pool with the specified initial capacity and no maximum. */
public Pool (int initialCapacity) {
this(initialCapacity, Integer.MAX_VALUE, false);
this(initialCapacity, Integer.MAX_VALUE);
}

/** @param max The maximum number of free objects to store in this pool. */
/** @param initialCapacity The initial size of the array supporting the pool. No objects are created/pre-allocated.
* Use {@link #fill(int) after instantiation if needed.
* @param max The maximum number of free objects to store in this pool. */
public Pool (int initialCapacity, int max) {
this(initialCapacity, max, false);
}

/** @param initialCapacity The initial size of the array supporting the pool. No objects are created unless preFill is true.
* @param max The maximum number of free objects to store in this pool.
* @param preFill Whether to pre-fill the pool with objects. The number of pre-filled objects will be equal to the initial
* capacity. */
public Pool (int initialCapacity, int max, boolean preFill) {
if (initialCapacity > max && preFill)
throw new IllegalArgumentException("max must be larger than initialCapacity if preFill is set to true.");
freeObjects = new Array(false, initialCapacity);
this.max = max;
if (preFill) {
for (int i = 0; i < initialCapacity; i++)
freeObjects.add(newObject());
peak = freeObjects.size;
}
}

abstract protected T newObject ();
Expand Down
10 changes: 3 additions & 7 deletions gdx/src/com/badlogic/gdx/utils/ReflectionPool.java
Expand Up @@ -27,19 +27,15 @@ public class ReflectionPool<T> extends Pool<T> {
private final Constructor constructor;

public ReflectionPool (Class<T> type) {
this(type, 16, Integer.MAX_VALUE, false);
this(type, 16, Integer.MAX_VALUE);
}

public ReflectionPool (Class<T> type, int initialCapacity) {
this(type, initialCapacity, Integer.MAX_VALUE, false);
this(type, initialCapacity, Integer.MAX_VALUE);
}

public ReflectionPool (Class<T> type, int initialCapacity, int max) {
this(type, initialCapacity, max, false);
}

public ReflectionPool (Class<T> type, int initialCapacity, int max, boolean preFill) {
super(initialCapacity, max, preFill);
super(initialCapacity, max);
constructor = findConstructor(type);
if (constructor == null)
throw new RuntimeException("Class cannot be created (missing no-arg constructor): " + type.getName());
Expand Down

0 comments on commit c3f77fd

Please sign in to comment.