Skip to content

Commit

Permalink
Avoid ArrayList#addAll when setting bucket priorities.
Browse files Browse the repository at this point in the history
Fixes #3296

PiperOrigin-RevId: 276290565
  • Loading branch information
sjudd authored and glide-copybara-robot committed Oct 23, 2019
1 parent 690f815 commit cb7bc49
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public final class ImageHeaderParserUtils {
// 5MB. This is the max image header size we can handle, we preallocate a much smaller buffer but
// will resize up to this amount if necessary.
private static final int MARK_POSITION = 5 * 1024 * 1024;
private static final int MARK_READ_LIMIT = 5 * 1024 * 1024;

private ImageHeaderParserUtils() {}

Expand All @@ -33,7 +33,7 @@ public static ImageType getType(
is = new RecyclableBufferedInputStream(is, byteArrayPool);
}

is.mark(MARK_POSITION);
is.mark(MARK_READ_LIMIT);
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0, size = parsers.size(); i < size; i++) {
ImageHeaderParser parser = parsers.get(i);
Expand Down Expand Up @@ -84,7 +84,7 @@ public static int getOrientation(
is = new RecyclableBufferedInputStream(is, byteArrayPool);
}

is.mark(MARK_POSITION);
is.mark(MARK_READ_LIMIT);
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0, size = parsers.size(); i < size; i++) {
ImageHeaderParser parser = parsers.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public class ResourceDecoderRegistry {
public synchronized void setBucketPriorityList(@NonNull List<String> buckets) {
List<String> previousBuckets = new ArrayList<>(bucketPriorityList);
bucketPriorityList.clear();
bucketPriorityList.addAll(buckets);
// new ArrayList(List) and ArrayList#addAll(List) are both broken on some verisons of Android,
// see #3296
for (String bucket : buckets) {
bucketPriorityList.add(buckets);
}
for (String previousBucket : previousBuckets) {
if (!buckets.contains(previousBucket)) {
// Keep any buckets from the previous list that aren't included here, but but them at the
Expand Down

0 comments on commit cb7bc49

Please sign in to comment.