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:
parent
1d2b2377cf
commit
e769130829
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user