Skip to content

Remove sizing from Recycler#obtain #39975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ protected AbstractRecycler(Recycler.C<T> c) {
this.c = c;
}

@Override
public V<T> obtain() {
return obtain(-1);
}

@Override
public void close() {
// no-op by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public abstract class AbstractRecyclerC<T> implements Recycler.C<T> {

@Override
public abstract T newInstance(int sizing);
public abstract T newInstance();

@Override
public abstract void recycle(T value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ConcurrentDequeRecycler<T> extends DequeRecycler<T> {
final AtomicInteger size;

public ConcurrentDequeRecycler(C<T> c, int maxSize) {
super(c, ConcurrentCollections.<T>newDeque(), maxSize);
super(c, ConcurrentCollections.newDeque(), maxSize);
this.size = new AtomicInteger();
}

Expand All @@ -45,8 +45,8 @@ public void close() {
}

@Override
public V<T> obtain(int sizing) {
final V<T> v = super.obtain(sizing);
public V<T> obtain() {
final V<T> v = super.obtain();
if (v.isRecycled()) {
size.decrementAndGet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public void close() {
}

@Override
public V<T> obtain(int sizing) {
public V<T> obtain() {
final T v = deque.pollFirst();
if (v == null) {
return new DV(c.newInstance(sizing), false);
return new DV(c.newInstance(), false);
}
return new DV(v, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ protected Recycler.V<T> wrap(Recycler.V<T> delegate) {
return delegate;
}

@Override
public Recycler.V<T> obtain(int sizing) {
return wrap(getDelegate().obtain(sizing));
}

@Override
public Recycler.V<T> obtain() {
return wrap(getDelegate().obtain());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public NoneRecycler(C<T> c) {
}

@Override
public V<T> obtain(int sizing) {
return new NV<>(c.newInstance(sizing));
public V<T> obtain() {
return new NV<>(c.newInstance());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface Factory<T> {
interface C<T> {

/** Create a new empty instance of the given size. */
T newInstance(int sizing);
T newInstance();

/** Recycle the data. This operation is called when the data structure is released. */
void recycle(T value);
Expand All @@ -57,5 +57,4 @@ interface V<T> extends Releasable {

V<T> obtain();

V<T> obtain(int sizing);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ protected Recycler<T> getDelegate() {
return recycler;
}

@Override
public Recycler.V<T> obtain(int sizing) {
synchronized (lock) {
return super.obtain(sizing);
}
}

@Override
public Recycler.V<T> obtain() {
synchronized (lock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public PageCacheRecycler(Settings settings) {
final int maxBytePageCount = (int) (bytesWeight * maxPageCount / totalWeight);
bytePage = build(type, maxBytePageCount, availableProcessors, new AbstractRecyclerC<byte[]>() {
@Override
public byte[] newInstance(int sizing) {
public byte[] newInstance() {
return new byte[BYTE_PAGE_SIZE];
}
@Override
Expand All @@ -119,7 +119,7 @@ public void recycle(byte[] value) {
final int maxIntPageCount = (int) (intsWeight * maxPageCount / totalWeight);
intPage = build(type, maxIntPageCount, availableProcessors, new AbstractRecyclerC<int[]>() {
@Override
public int[] newInstance(int sizing) {
public int[] newInstance() {
return new int[INT_PAGE_SIZE];
}
@Override
Expand All @@ -131,7 +131,7 @@ public void recycle(int[] value) {
final int maxLongPageCount = (int) (longsWeight * maxPageCount / totalWeight);
longPage = build(type, maxLongPageCount, availableProcessors, new AbstractRecyclerC<long[]>() {
@Override
public long[] newInstance(int sizing) {
public long[] newInstance() {
return new long[LONG_PAGE_SIZE];
}
@Override
Expand All @@ -143,7 +143,7 @@ public void recycle(long[] value) {
final int maxObjectPageCount = (int) (objectsWeight * maxPageCount / totalWeight);
objectPage = build(type, maxObjectPageCount, availableProcessors, new AbstractRecyclerC<Object[]>() {
@Override
public Object[] newInstance(int sizing) {
public Object[] newInstance() {
return new Object[OBJECT_PAGE_SIZE];
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class AbstractRecyclerTestCase extends ESTestCase {
protected static final Recycler.C<byte[]> RECYCLER_C = new AbstractRecyclerC<byte[]>() {

@Override
public byte[] newInstance(int sizing) {
public byte[] newInstance() {
byte[] value = new byte[10];
// "fresh" is intentionally not 0 to ensure we covered this code path
Arrays.fill(value, FRESH);
Expand Down