[refactor] Refactor VM#getInstancesMap() with Map#computeIfAbsent()

Test: atest MicrodroidTests

Change-Id: I664cf4471573a38ab51e40736b1b6bae9614f6b2
This commit is contained in:
Alice Wang 2022-11-10 15:46:22 +00:00
parent 2acbb01203
commit b04942f337
1 changed files with 1 additions and 8 deletions

View File

@ -282,14 +282,7 @@ public class VirtualMachine implements AutoCloseable {
@GuardedBy("sCreateLock") @GuardedBy("sCreateLock")
@NonNull @NonNull
private static Map<String, WeakReference<VirtualMachine>> getInstancesMap(Context context) { private static Map<String, WeakReference<VirtualMachine>> getInstancesMap(Context context) {
Map<String, WeakReference<VirtualMachine>> instancesMap; return sInstances.computeIfAbsent(context, unused -> new HashMap<>());
if (sInstances.containsKey(context)) {
instancesMap = sInstances.get(context);
} else {
instancesMap = new HashMap<>();
sInstances.put(context, instancesMap);
}
return instancesMap;
} }
@NonNull @NonNull