mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 11:42:22 +08:00
perf(selector): 选择器优先比较逻辑
This commit is contained in:
parent
4d07d46e09
commit
699ad8b568
|
@ -8,22 +8,29 @@ sealed class CompareOperator(val key: String) {
|
|||
val allSubClasses = listOf(
|
||||
Equal,
|
||||
NotEqual,
|
||||
Start,
|
||||
NotStart,
|
||||
Include,
|
||||
NotInclude,
|
||||
End,
|
||||
NotEnd,
|
||||
Less,
|
||||
LessEqual,
|
||||
More,
|
||||
MoreEqual
|
||||
Start, NotStart, Include, NotInclude, End, NotEnd, Less, LessEqual, More, MoreEqual
|
||||
).sortedBy { -it.key.length }
|
||||
|
||||
// example
|
||||
// id="com.lptiyu.tanke:id/ab1"
|
||||
// id="com.lptiyu.tanke:id/ab2"
|
||||
private fun CharSequence.contentReversedEquals(other: CharSequence): Boolean {
|
||||
if (this === other) return true
|
||||
if (this.length != other.length) return false
|
||||
for (i in this.length - 1 downTo 0) {
|
||||
if (this[i] != other[i]) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
object Equal : CompareOperator("=") {
|
||||
override fun compare(left: Any?, right: Any?): Boolean {
|
||||
return if (left is CharSequence && right is CharSequence) left.contentEquals(right) else left == right
|
||||
return if (left is CharSequence && right is CharSequence) {
|
||||
left.contentReversedEquals(right)
|
||||
} else {
|
||||
left == right
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,12 @@ data class PropertySegment(
|
|||
object : NodeMatchFc {
|
||||
override fun <T> invoke(node: T, transform: Transform<T>): Boolean {
|
||||
val str = transform.getName(node) ?: return false
|
||||
return (str.contentEquals(name) || (str.endsWith(name) && str[str.length - name.length - 1] == '.'))
|
||||
if (str.length == name.length) {
|
||||
return str.contentEquals(name)
|
||||
} else if (str.length > name.length) {
|
||||
return str[str.length - name.length - 1] == '.' && str.endsWith(name)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user