fix: avoid unnecessary attribute lookup

This commit is contained in:
Akash Yadav
2022-11-19 09:42:57 +05:30
parent 28d7709c6f
commit 39803a835c
@@ -49,7 +49,7 @@ constructor(
updateAttribute(attribute)
} else {
this.attributes.add(attribute)
updateAttribute(attribute)
applyAttribute(attribute)
}
}
@@ -61,6 +61,14 @@ constructor(
override fun updateAttribute(attribute: IAttribute) {
val existing = findAttribute(attribute) ?: throw IllegalArgumentException("Attribute '${attribute.name}' not found")
existing.value = attribute.value
applyAttribute(existing)
}
override fun findAttribute(namespaceUri: String, name: String): IAttribute? {
return this.attributes.find { it.namespace.uri == namespaceUri && it.name == name }
}
protected open fun applyAttribute(attribute: IAttribute) {
val adapter = AttributeAdapterIndex.getAdapter(name)
if (adapter == null) {
log.warn("No attribute adapter found for view $name")
@@ -69,10 +77,6 @@ constructor(
adapter.apply(this, attribute)
}
override fun findAttribute(namespaceUri: String, name: String): IAttribute? {
return this.attributes.find { it.namespace.uri == namespaceUri && it.name == name }
}
protected open fun hasAttribute(attribute: IAttribute): Boolean {
return hasAttribute(attribute.namespace.uri, attribute.name)
}