diff options
| author | JosJuice <josjuice@gmail.com> | 2021-08-24 15:24:52 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2021-08-24 15:35:40 +0200 |
| commit | 719930bb390ed0020b99a7942289d83218e99d69 (patch) | |
| tree | da758c7b1d5f038a99ae8bd00ac752cb9155ca5e /Source/Android/app/src/main/java | |
| parent | fb265b610de08df5509e56beeb3dbff68f7d4396 (diff) | |
Android: Add fast path to addOrGet
This path isn't really any faster in the normal case,
but it does let us skip waiting for the lock to be available,
which makes a huge difference if the lock is already taken.
Diffstat (limited to 'Source/Android/app/src/main/java')
| -rw-r--r-- | Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java index a8ecc367c9..3be5fb039f 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java @@ -159,9 +159,20 @@ public final class GameFileCacheService extends IntentService public static GameFile addOrGet(String gamePath) { - // The existence of this one function, which is called from one - // single place, forces us to use synchronization in onHandleIntent... - // A bit annoying, but should be good enough for now + // Common case: The game is in the cache, so just grab it from there. + // (Actually, addOrGet already checks for this case, but we want to avoid calling it if possible + // because onHandleIntent may hold a lock on gameFileCache for extended periods of time.) + GameFile[] allGames = gameFiles.get(); + for (GameFile game : allGames) + { + if (game.getPath().equals(gamePath)) + { + return game; + } + } + + // Unusual case: The game wasn't found in the cache. + // Scan the game and add it to the cache so that we can return it. synchronized (gameFileCache) { return gameFileCache.addOrGet(gamePath); |
