Skip to content

Commit

Permalink
Cleanup (#2722)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX authored and sjudd committed Dec 18, 2017
1 parent cfae30a commit 36e0b80
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private WaitModelLoader(ModelLoader<Model, Data> wrapped) {
@Nullable
@Override
public LoadData<Data> buildLoadData(
WaitModel<Model> waitModel, int width, int height, Options options) {
@NonNull WaitModel<Model> waitModel, int width, int height, @NonNull Options options) {
LoadData<Data> wrappedLoadData = wrapped
.buildLoadData(waitModel.wrapped, width, height, options);
if (wrappedLoadData == null) {
Expand All @@ -42,7 +42,7 @@ public LoadData<Data> buildLoadData(
}

@Override
public boolean handles(WaitModel<Model> waitModel) {
public boolean handles(@NonNull WaitModel<Model> waitModel) {
return wrapped.handles(waitModel.wrapped);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public static ImageType getType(List<ImageHeaderParser> parsers, @Nullable Input
}

is.mark(MARK_POSITION);
int size = parsers.size();
for (int i = 0; i < size; i++) {
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0, size = parsers.size(); i < size; i++) {
ImageHeaderParser parser = parsers.get(i);
try {
ImageType type = parser.getType(is);
Expand All @@ -54,8 +54,8 @@ public static ImageType getType(List<ImageHeaderParser> parsers, @Nullable ByteB
return ImageType.UNKNOWN;
}

int size = parsers.size();
for (int i = 0; i < size; i++) {
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0, size = parsers.size(); i < size; i++) {
ImageHeaderParser parser = parsers.get(i);
ImageType type = parser.getType(buffer);
if (type != ImageType.UNKNOWN) {
Expand All @@ -78,8 +78,8 @@ public static int getOrientation(List<ImageHeaderParser> parsers, @Nullable Inpu
}

is.mark(MARK_POSITION);
int size = parsers.size();
for (int i = 0; i < size; i++) {
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0, size = parsers.size(); i < size; i++) {
ImageHeaderParser parser = parsers.get(i);
try {
int orientation = parser.getOrientation(is, byteArrayPool);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ <Z> ResourceEncoder<Z> getResultEncoder(Resource<Z> resource) {

boolean isSourceKey(Key key) {
List<LoadData<?>> loadData = getLoadData();
int size = loadData.size();
for (int i = 0; i < size; i++) {
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0, size = loadData.size(); i < size; i++) {
LoadData<?> current = loadData.get(i);
if (current.sourceKey.equals(key)) {
return true;
Expand All @@ -195,8 +195,8 @@ List<LoadData<?>> getLoadData() {
isLoadDataSet = true;
loadData.clear();
List<ModelLoader<Object, ?>> modelLoaders = glideContext.getRegistry().getModelLoaders(model);
int size = modelLoaders.size();
for (int i = 0; i < size; i++) {
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0, size = modelLoaders.size(); i < size; i++) {
ModelLoader<Object, ?> modelLoader = modelLoaders.get(i);
LoadData<?> current =
modelLoader.buildLoadData(model, width, height, options);
Expand All @@ -213,8 +213,8 @@ List<Key> getCacheKeys() {
isCacheKeysSet = true;
cacheKeys.clear();
List<LoadData<?>> loadData = getLoadData();
int size = loadData.size();
for (int i = 0; i < size; i++) {
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0, size = loadData.size(); i < size; i++) {
LoadData<?> data = loadData.get(i);
if (!cacheKeys.contains(data.sourceKey)) {
cacheKeys.add(data.sourceKey);
Expand Down
33 changes: 18 additions & 15 deletions library/src/main/java/com/bumptech/glide/load/engine/DecodeJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,21 +559,24 @@ public Resource<Z> onResourceDecoded(Resource<Z> decoded) {
throw new Registry.NoResultEncoderAvailableException(transformed.get().getClass());
}
final Key key;
if (encodeStrategy == EncodeStrategy.SOURCE) {
key = new DataCacheKey(currentSourceKey, signature);
} else if (encodeStrategy == EncodeStrategy.TRANSFORMED) {
key =
new ResourceCacheKey(
decodeHelper.getArrayPool(),
currentSourceKey,
signature,
width,
height,
appliedTransformation,
resourceSubClass,
options);
} else {
throw new IllegalArgumentException("Unknown strategy: " + encodeStrategy);
switch (encodeStrategy) {
case SOURCE:
key = new DataCacheKey(currentSourceKey, signature);
break;
case TRANSFORMED:
key =
new ResourceCacheKey(
decodeHelper.getArrayPool(),
currentSourceKey,
signature,
width,
height,
appliedTransformation,
resourceSubClass,
options);
break;
default:
throw new IllegalArgumentException("Unknown strategy: " + encodeStrategy);
}

LockedResource<Z> lockedResult = LockedResource.obtain(transformed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private Resource<ResourceType> decodeResource(DataRewinder<DataType> rewinder, i
private Resource<ResourceType> decodeResourceWithList(DataRewinder<DataType> rewinder, int width,
int height, Options options, List<Throwable> exceptions) throws GlideException {
Resource<ResourceType> result = null;
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0, size = decoders.size(); i < size; i++) {
ResourceDecoder<DataType, ResourceType> decoder = decoders.get(i);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ void handleResultOnMainThread() {
engineResource.acquire();
listener.onEngineJobComplete(this, key, engineResource);

int size = cbs.size();
for (int i = 0; i < size; i++) {
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0, size = cbs.size(); i < size; i++) {
ResourceCallback cb = cbs.get(i);
if (!isInIgnoredCallbacks(cb)) {
engineResource.acquire();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public Resource<Transcode> load(DataRewinder<Data> rewinder, Options options, in
private Resource<Transcode> loadWithExceptionList(DataRewinder<Data> rewinder, Options options,
int width, int height, DecodePath.DecodeCallback<ResourceType> decodeCallback,
List<Throwable> exceptions) throws GlideException {
int size = decodePaths.size();
Resource<Transcode> result = null;
for (int i = 0; i < size; i++) {
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0, size = decodePaths.size(); i < size; i++) {
DecodePath<Data, ResourceType, Transcode> path = decodePaths.get(i);
try {
result = path.decode(rewinder, width, height, options, decodeCallback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ private static LruPoolStrategy getDefaultStrategy() {

@TargetApi(Build.VERSION_CODES.O)
private static Set<Bitmap.Config> getDefaultAllowedConfigs() {
Set<Bitmap.Config> configs = new HashSet<>();
configs.addAll(Arrays.asList(Bitmap.Config.values()));
Set<Bitmap.Config> configs = new HashSet<>(Arrays.asList(Bitmap.Config.values()));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// GIFs, among other types, end up with a native Bitmap config that doesn't map to a java
// config and is treated as null in java code. On KitKat+ these Bitmaps can be reconfigured
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private <Model, Data> void tearDown(
List<ModelLoader<A, ?>> modelLoaders = getModelLoadersForClass(getClass(model));
int size = modelLoaders.size();
List<ModelLoader<A, ?>> filteredLoaders = new ArrayList<>(size);
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0; i < size; i++) {
ModelLoader<A, ?> loader = modelLoaders.get(i);
if (loader.handles(model)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public LoadData<Data> buildLoadData(@NonNull Model model, int width, int height,
Key sourceKey = null;
int size = modelLoaders.size();
List<DataFetcher<Data>> fetchers = new ArrayList<>(size);
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0; i < size; i++) {
ModelLoader<Model, Data> modelLoader = modelLoaders.get(i);
if (modelLoader.handles(model)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,19 @@ private static int parseExifSegment(RandomAccessReader segmentData) {

short byteOrderIdentifier = segmentData.getInt16(headerOffsetSize);
final ByteOrder byteOrder;
if (byteOrderIdentifier == MOTOROLA_TIFF_MAGIC_NUMBER) {
byteOrder = ByteOrder.BIG_ENDIAN;
} else if (byteOrderIdentifier == INTEL_TIFF_MAGIC_NUMBER) {
byteOrder = ByteOrder.LITTLE_ENDIAN;
} else {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Unknown endianness = " + byteOrderIdentifier);
}
byteOrder = ByteOrder.BIG_ENDIAN;
switch (byteOrderIdentifier) {
case MOTOROLA_TIFF_MAGIC_NUMBER:
byteOrder = ByteOrder.BIG_ENDIAN;
break;
case INTEL_TIFF_MAGIC_NUMBER:
byteOrder = ByteOrder.LITTLE_ENDIAN;
break;
default:
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Unknown endianness = " + byteOrderIdentifier);
}
byteOrder = ByteOrder.BIG_ENDIAN;
break;
}

segmentData.order(byteOrder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LoadPathCache {
Object.class,
Object.class,
Collections.singletonList(
new DecodePath<Object, Object, Object>(
new DecodePath<>(
Object.class,
Object.class,
Object.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public synchronized <Z> void prepend(Class<Z> resourceClass, ResourceEncoder<Z>
@SuppressWarnings("unchecked")
@Nullable
public synchronized <Z> ResourceEncoder<Z> get(Class<Z> resourceClass) {
int size = encoders.size();
for (int i = 0; i < size; i++) {
//noinspection ForLoopReplaceableByForEach to improve perf
for (int i = 0, size = encoders.size(); i < size; i++) {
Entry<?> entry = encoders.get(i);
if (entry.handles(resourceClass)) {
return (ResourceEncoder<Z>) entry.encoder;
Expand Down

0 comments on commit 36e0b80

Please sign in to comment.