1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-25 21:23:55 +08:00

Improve ComponentStorage.plus: accept nullable arguments

This commit is contained in:
Him188 2021-05-11 09:01:12 +08:00
parent 1d2b2377cf
commit e769130829

View File

@ -31,10 +31,17 @@ internal interface ComponentStorage {
val keys: Set<ComponentKey<*>>
override fun toString(): String
companion object {
val EMPTY: ComponentStorage by lazy { ConcurrentComponentStorage() }
}
}
internal operator fun ComponentStorage.plus(fallback: ComponentStorage): ComponentStorage =
CombinedComponentStorage(this, fallback)
internal operator fun ComponentStorage?.plus(fallback: ComponentStorage?): ComponentStorage {
if (this == null) return fallback ?: return ComponentStorage.EMPTY
if (fallback == null) return this
return CombinedComponentStorage(this, fallback)
}
private class CombinedComponentStorage(
val main: ComponentStorage,