Skip to content

Commit 2ce8847

Browse files
committed
Merge pull request #720 from square/dimitris/minor-cleanup
Remove bitmap hunter warnings and unneccesary checks
2 parents 6519aa0 + 06583b1 commit 2ce8847

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

picasso/src/main/java/com/squareup/picasso/BitmapHunter.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ class BitmapHunter implements Runnable {
8585
Priority priority;
8686

8787
BitmapHunter(Picasso picasso, Dispatcher dispatcher, Cache cache, Stats stats, Action action,
88-
RequestHandler requestHandler) {
88+
RequestHandler requestHandler) {
8989
this.sequence = SEQUENCE_GENERATOR.incrementAndGet();
9090
this.picasso = picasso;
9191
this.dispatcher = dispatcher;
9292
this.cache = cache;
9393
this.stats = stats;
94+
this.action = action;
9495
this.key = action.getKey();
9596
this.data = action.getRequest();
97+
this.priority = action.getPriority();
9698
this.skipMemoryCache = action.skipCache;
9799
this.requestHandler = requestHandler;
98100
this.retryCount = requestHandler.getRetryCount();
99-
this.action = action;
100-
this.priority = (action != null ? action.getPriority() : LOW);
101101
}
102102

103103
@Override public void run() {
@@ -242,9 +242,10 @@ private Priority computeNewPriority() {
242242
Priority newPriority = LOW;
243243

244244
boolean hasMultiple = actions != null && !actions.isEmpty();
245+
boolean hasAny = action != null || hasMultiple;
245246

246247
// Hunter has no requests, low priority.
247-
if (actions == null && !hasMultiple) {
248+
if (!hasAny) {
248249
return newPriority;
249250
}
250251

@@ -253,6 +254,7 @@ private Priority computeNewPriority() {
253254
}
254255

255256
if (hasMultiple) {
257+
//noinspection ForLoopReplaceableByForEach
256258
for (int i = 0, n = actions.size(); i < n; i++) {
257259
Priority actionPriority = actions.get(i).getPriority();
258260
if (actionPriority.ordinal() > newPriority.ordinal()) {
@@ -338,8 +340,8 @@ static void updateThreadName(Request data) {
338340
Thread.currentThread().setName(builder.toString());
339341
}
340342

341-
static BitmapHunter forRequest(Picasso picasso, Dispatcher dispatcher,
342-
Cache cache, Stats stats, Action action) {
343+
static BitmapHunter forRequest(Picasso picasso, Dispatcher dispatcher, Cache cache, Stats stats,
344+
Action action) {
343345
Request request = action.getRequest();
344346
List<RequestHandler> requestHandlers = picasso.getRequestHandlers();
345347

@@ -364,9 +366,8 @@ static Bitmap applyCustomTransformations(List<Transformation> transformations, B
364366
} catch (final RuntimeException e) {
365367
Picasso.HANDLER.post(new Runnable() {
366368
@Override public void run() {
367-
throw new RuntimeException("Transformation "
368-
+ transformation.key()
369-
+ " crashed with exception.", e);
369+
throw new RuntimeException(
370+
"Transformation " + transformation.key() + " crashed with exception.", e);
370371
}
371372
});
372373
return null;
@@ -468,10 +469,10 @@ static Bitmap transformResult(Request data, Bitmap result, int exifRotation) {
468469
// If an explicit target size has been specified and they do not match the results bounds,
469470
// pre-scale the existing matrix appropriately.
470471
// Keep aspect ratio if one dimension is set to 0.
471-
float sx = targetWidth != 0 ? targetWidth / (float) inWidth
472-
: targetHeight / (float) inHeight;
473-
float sy = targetHeight != 0 ? targetHeight / (float) inHeight
474-
: targetWidth / (float) inWidth;
472+
float sx =
473+
targetWidth != 0 ? targetWidth / (float) inWidth : targetHeight / (float) inHeight;
474+
float sy =
475+
targetHeight != 0 ? targetHeight / (float) inHeight : targetWidth / (float) inWidth;
475476
matrix.preScale(sx, sy);
476477
}
477478
}

0 commit comments

Comments
 (0)