fix: cache XmlRegistry instances

This commit is contained in:
Akash Yadav
2023-09-12 18:15:47 +05:30
parent 461bded415
commit c440265396
3 changed files with 14 additions and 4 deletions
@@ -43,10 +43,12 @@ interface ResourceTableRegistry : XmlRegistry<ResourceTable> {
@JvmStatic
val COMPLETION_MANIFEST_ATTR_RES = Lookup.Key<ResourceTable>()
private var sInstance: ResourceTableRegistry? = null
@JvmStatic
fun getInstance(): ResourceTableRegistry {
val klass = ResourceTableRegistry::class.java
return ServiceLoader.load(klass, klass.classLoader).findFirstOrThrow()
return sInstance ?: ServiceLoader.load(klass, klass.classLoader).findFirstOrThrow().also { sInstance = it }
}
}
@@ -30,12 +30,17 @@ import com.itsaky.androidide.xml.registry.XmlRegistry
* @author Akash Yadav
*/
interface ApiVersionsRegistry : XmlRegistry<ApiVersions> {
companion object {
private var sInstance: ApiVersionsRegistry? = null
/** Get the default instance of [ApiVersionsRegistry]. */
@JvmStatic fun getInstance(): ApiVersionsRegistry {
@JvmStatic
fun getInstance(): ApiVersionsRegistry {
val klass = ApiVersionsRegistry::class.java
return ServiceLoader.load(klass, klass.classLoader).findFirstOrThrow()
return sInstance ?: ServiceLoader.load(klass, klass.classLoader).findFirstOrThrow()
.also { sInstance = it }
}
}
}
@@ -30,11 +30,14 @@ interface WidgetTableRegistry : XmlRegistry<WidgetTable> {
companion object {
private var sInstance: WidgetTableRegistry? = null
/** Get the default instance of [WidgetTableRegistry]. */
@JvmStatic
fun getInstance(): WidgetTableRegistry {
val klass = WidgetTableRegistry::class.java
return ServiceLoader.load(klass, klass.classLoader).findFirstOrThrow()
return sInstance ?: ServiceLoader.load(klass, klass.classLoader).findFirstOrThrow()
.also { sInstance = it }
}
}
}