Skip to content

Commit

Permalink
Minimize stat() syscall on Glide init.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 351620050
  • Loading branch information
sjudd authored and glide-copybara-robot committed Jan 13, 2021
1 parent 8f77079 commit 5acc99f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions library/src/main/java/com/bumptech/glide/Glide.java
Expand Up @@ -162,11 +162,11 @@ public static File getPhotoCacheDir(@NonNull Context context, @NonNull String ca
File cacheDir = context.getCacheDir();
if (cacheDir != null) {
File result = new File(cacheDir, cacheName);
if (!result.mkdirs() && (!result.exists() || !result.isDirectory())) {
// File wasn't able to create a directory, or the result exists but not a directory
return null;
if (result.isDirectory() || result.mkdirs()) {
return result;
}
return result;
// File wasn't able to create a directory, or the result exists but not a directory
return null;
}
if (Log.isLoggable(TAG, Log.ERROR)) {
Log.e(TAG, "default disk cache dir is null");
Expand Down
Expand Up @@ -65,10 +65,10 @@ public DiskCache build() {
return null;
}

if (!cacheDir.mkdirs() && (!cacheDir.exists() || !cacheDir.isDirectory())) {
return null;
if (cacheDir.isDirectory() || cacheDir.mkdirs()) {
return DiskLruCacheWrapper.create(cacheDir, diskCacheSize);
}

return DiskLruCacheWrapper.create(cacheDir, diskCacheSize);
return null;
}
}
Expand Up @@ -804,9 +804,7 @@ public File getFile(int index) throws IOException {
written[index] = true;
}
File dirtyFile = entry.getDirtyFile(index);
if (!directory.exists()) {
directory.mkdirs();
}
directory.mkdirs();
return dirtyFile;
}
}
Expand Down

0 comments on commit 5acc99f

Please sign in to comment.