Skip to content

Commit 785785a

Browse files
authored
[AI] Use getOrPut to update the multi resource map (#7165)
That method is cleaner, and the intended way, of inserting a value into a map if it's missing. Tag: cleanup
1 parent 88feb63 commit 785785a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

firebase-ai/src/main/kotlin/com/google/firebase/ai/FirebaseAIMultiResourceComponent.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ internal class FirebaseAIMultiResourceComponent(
4141

4242
fun get(backend: GenerativeBackend): FirebaseAI =
4343
synchronized(this) {
44-
instances[backend.location]
45-
?: FirebaseAI(
46-
app,
47-
backend,
48-
blockingDispatcher,
49-
appCheckProvider,
50-
internalAuthProvider,
51-
)
52-
.also { instances[backend.location] = it }
44+
instances.getOrPut(backend.location) {
45+
FirebaseAI(
46+
app,
47+
backend,
48+
blockingDispatcher,
49+
appCheckProvider,
50+
internalAuthProvider,
51+
)
52+
}
5353
}
5454
}

0 commit comments

Comments
 (0)