Skip to content

Commit cdf1fdf

Browse files
sjuddglide-copybara-robot
authored andcommitted
Avoid ArrayList#addAll when setting bucket priorities.
Fixes #3296 PiperOrigin-RevId: 276290565
1 parent 690f815 commit cdf1fdf

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

library/src/main/java/com/bumptech/glide/load/ImageHeaderParserUtils.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public final class ImageHeaderParserUtils {
1515
// 5MB. This is the max image header size we can handle, we preallocate a much smaller buffer but
1616
// will resize up to this amount if necessary.
17-
private static final int MARK_POSITION = 5 * 1024 * 1024;
17+
private static final int MARK_READ_LIMIT = 5 * 1024 * 1024;
1818

1919
private ImageHeaderParserUtils() {}
2020

@@ -33,7 +33,7 @@ public static ImageType getType(
3333
is = new RecyclableBufferedInputStream(is, byteArrayPool);
3434
}
3535

36-
is.mark(MARK_POSITION);
36+
is.mark(MARK_READ_LIMIT);
3737
//noinspection ForLoopReplaceableByForEach to improve perf
3838
for (int i = 0, size = parsers.size(); i < size; i++) {
3939
ImageHeaderParser parser = parsers.get(i);
@@ -84,7 +84,7 @@ public static int getOrientation(
8484
is = new RecyclableBufferedInputStream(is, byteArrayPool);
8585
}
8686

87-
is.mark(MARK_POSITION);
87+
is.mark(MARK_READ_LIMIT);
8888
//noinspection ForLoopReplaceableByForEach to improve perf
8989
for (int i = 0, size = parsers.size(); i < size; i++) {
9090
ImageHeaderParser parser = parsers.get(i);

library/src/main/java/com/bumptech/glide/provider/ResourceDecoderRegistry.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ public class ResourceDecoderRegistry {
2020
public synchronized void setBucketPriorityList(@NonNull List<String> buckets) {
2121
List<String> previousBuckets = new ArrayList<>(bucketPriorityList);
2222
bucketPriorityList.clear();
23-
bucketPriorityList.addAll(buckets);
23+
// new ArrayList(List) and ArrayList#addAll(List) are both broken on some verisons of Android,
24+
// see #3296
25+
for (String bucket : buckets) {
26+
bucketPriorityList.add(buckets);
27+
}
2428
for (String previousBucket : previousBuckets) {
2529
if (!buckets.contains(previousBucket)) {
2630
// Keep any buckets from the previous list that aren't included here, but but them at the

0 commit comments

Comments
 (0)