Skip to content

Commit

Permalink
Remove Request#recycle()
Browse files Browse the repository at this point in the history
It's now unused.

PiperOrigin-RevId: 263792894
  • Loading branch information
sjudd authored and glide-copybara-robot committed Aug 16, 2019
1 parent b3b1216 commit 01addba
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,6 @@ private <Y extends Target<TranscodeType>> Y into(
Request previous = target.getRequest();
if (request.isEquivalentTo(previous)
&& !isSkipMemoryCacheWithCompletePreviousRequest(options, previous)) {
request.recycle();
// If the request is completed, beginning again will ensure the result is re-delivered,
// triggering RequestListeners and Targets. If the request is failed, beginning again will
// restart the request, giving it another chance to complete. If the request is already
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ synchronized boolean untrack(@NonNull Target<?> target) {
return true;
}

if (requestTracker.clearRemoveAndRecycle(request)) {
if (requestTracker.clearAndRemove(request)) {
targetTracker.untrack(target);
target.setRequest(null);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ void addRequest(Request request) {
* Stops tracking the given request, clears, and recycles it, and returns {@code true} if the
* request was removed or invalid or {@code false} if the request was not found.
*/
public boolean clearRemoveAndRecycle(@Nullable Request request) {
// It's safe for us to recycle because this is only called when the user is explicitly clearing
// a Target so we know that there are no remaining references to the Request.
return clearRemoveAndMaybeRecycle(request, /*isSafeToRecycle=*/ true);
}

private boolean clearRemoveAndMaybeRecycle(@Nullable Request request, boolean isSafeToRecycle) {
public boolean clearAndRemove(@Nullable Request request) {
if (request == null) {
// If the Request is null, the request is already cleared and we don't need to search further
// for its owner.
Expand All @@ -76,9 +70,6 @@ private boolean clearRemoveAndMaybeRecycle(@Nullable Request request, boolean is
isOwnedByUs = pendingRequests.remove(request) || isOwnedByUs;
if (isOwnedByUs) {
request.clear();
if (isSafeToRecycle) {
request.recycle();
}
}
return isOwnedByUs;
}
Expand Down Expand Up @@ -136,7 +127,7 @@ public void clearRequests() {
for (Request request : Util.getSnapshot(requests)) {
// It's unsafe to recycle the Request here because we don't know who might else have a
// reference to it.
clearRemoveAndMaybeRecycle(request, /*isSafeToRecycle=*/ false);
clearAndRemove(request);
}
pendingRequests.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,6 @@ public boolean isCleared() {
}
}

@Override
public void recycle() {
synchronized (requestLock) {
primary.recycle();
error.recycle();
}
}

@Override
public boolean isEquivalentTo(Request o) {
if (o instanceof ErrorRequestCoordinator) {
Expand Down
3 changes: 0 additions & 3 deletions library/src/main/java/com/bumptech/glide/request/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public interface Request {
/** Returns true if the request has been cleared. */
boolean isCleared();

/** Recycles the request object and releases its resources. */
void recycle();

/**
* Returns {@code true} if this {@link Request} is equivalent to the given {@link Request} (has
* all of the same options and sizes).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,6 @@ public boolean isCleared() {
}
}

@Override
public void recycle() {
// TODO: remove this method, it's a no-op.
}

@GuardedBy("requestLock")
private Drawable getErrorDrawable() {
if (errorDrawable == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,6 @@ public boolean isCleared() {
}
}

@Override
public void recycle() {
synchronized (requestLock) {
full.recycle();
thumb.recycle();
}
}

@Override
public boolean isEquivalentTo(Request o) {
if (o instanceof ThumbnailRequestCoordinator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,69 +27,54 @@ public void setUp() {
}

@Test
public void clearRequests_doesNotRecycleRequests() {
public void clearAndRemove_withRequestPreviouslyClearedInClearRequests_doesNothing() {
FakeRequest request = new FakeRequest();
tracker.addRequest(request);

tracker.clearRequests();
tracker.clearAndRemove(request);

assertThat(request.isCleared()).isTrue();
assertThat(request.isRecycled()).isFalse();
}

@Test
public void clearRemoveAndRecycle_withRequestPreviouslyClearedInClearRequests_doesNothing() {
FakeRequest request = new FakeRequest();
tracker.addRequest(request);

tracker.clearRequests();
tracker.clearRemoveAndRecycle(request);

assertThat(request.isCleared()).isTrue();
assertThat(request.isRecycled()).isFalse();
}

@Test
public void clearRemoveAndRecycle_withNullRequest_doesNothingAndReturnsTrue() {
assertThat(tracker.clearRemoveAndRecycle(null)).isTrue();
public void clearAndRemove_withNullRequest_doesNothingAndReturnsTrue() {
assertThat(tracker.clearAndRemove(null)).isTrue();
}

@Test
public void clearRemoveAndRecycle_withUnTrackedRequest_doesNothingAndReturnsFalse() {
public void clearAndRemove_withUnTrackedRequest_doesNothingAndReturnsFalse() {
FakeRequest request = new FakeRequest();

assertThat(tracker.clearRemoveAndRecycle(request)).isFalse();
assertThat(tracker.clearAndRemove(request)).isFalse();

assertThat(request.isCleared()).isFalse();
assertThat(request.isRecycled()).isFalse();
}

@Test
public void clearRemoveAndRecycle_withTrackedRequest_clearsRecyclesAndReturnsTrue() {
public void clearAndRemov_withTrackedRequest_clearssAndReturnsTrue() {
FakeRequest request = new FakeRequest();
tracker.addRequest(request);

assertThat(tracker.clearRemoveAndRecycle(request)).isTrue();
assertThat(tracker.clearAndRemove(request)).isTrue();
assertThat(request.isCleared()).isTrue();
assertThat(request.isRecycled()).isTrue();
}

@Test
public void clearRemoveAndRecycle_withAlreadyRemovedRequest_doesNothingAndReturnsFalse() {
public void clearAndRemove_withAlreadyRemovedRequest_doesNothingAndReturnsFalse() {
FakeRequest request = new FakeRequest();
tracker.addRequest(request);
tracker.clearRemoveAndRecycle(request);
assertThat(tracker.clearRemoveAndRecycle(request)).isFalse();
tracker.clearAndRemove(request);
assertThat(tracker.clearAndRemove(request)).isFalse();

assertThat(request.isCleared()).isTrue();
assertThat(request.isRecycled()).isTrue();
}

@Test
public void clearRequests_withPreviouslyClearedRequest_doesNotClearRequestAgain() {
FakeRequest request = new FakeRequest();
tracker.addRequest(request);
tracker.clearRemoveAndRecycle(request);
tracker.clearAndRemove(request);

tracker.clearRequests();

Expand Down Expand Up @@ -382,7 +367,6 @@ public void pause() {
private boolean isRunning;
private boolean isCleared;
private boolean isComplete;
private boolean isRecycled;

void setIsComplete() {
setIsComplete(true);
Expand All @@ -396,10 +380,6 @@ void setIsRunning() {
isRunning = true;
}

boolean isRecycled() {
return isRecycled;
}

boolean isPaused() {
return isPaused;
}
Expand Down Expand Up @@ -436,14 +416,6 @@ public boolean isCleared() {
return isCleared;
}

@Override
public void recycle() {
if (isRecycled) {
throw new IllegalStateException();
}
isRecycled = true;
}

@Override
public boolean isEquivalentTo(Request other) {
throw new UnsupportedOperationException();
Expand All @@ -460,7 +432,7 @@ private class ClearAndRemoveRequest implements Answer<Void> {

@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
tracker.clearRemoveAndRecycle(toRemove);
tracker.clearAndRemove(toRemove);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,6 @@ public void isCleared_primaryFailed_errorCancelled_returnsTrue() {
assertThat(coordinator.isCleared()).isTrue();
}

@Test
public void recycle_recyclesPrimaryAndError() {
coordinator.recycle();
verify(primary).recycle();
verify(error).recycle();
}

@Test
public void isEquivalentTo() {
assertThat(coordinator.isEquivalentTo(primary)).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,6 @@ public void pause_pausesThumbAndFullInOrder() {
order.verify(full).pause();
}

@Test
public void testRecyclesRequestsWhenRecycled() {
coordinator.recycle();
verify(thumb).recycle();
verify(full).recycle();
}

@Test
public void testCanSetImageReturnsTrueForFullRequestIfCoordinatorIsNull() {
coordinator = newCoordinator();
Expand Down

0 comments on commit 01addba

Please sign in to comment.