summaryrefslogtreecommitdiff
path: root/autofill-parser
diff options
context:
space:
mode:
authorFabian Henneke <FabianHenneke@users.noreply.github.com>2020-10-02 12:17:04 +0200
committerGitHub <noreply@github.com>2020-10-02 15:47:04 +0530
commit8f3fd99472b478ae9c50482627bfac49c67676be (patch)
tree21c4d8811048fb57df8a9a871cbcc9e5edba313f /autofill-parser
parent880806b4480dfd1c02bbb6cd2bfa9e65967d62a9 (diff)
Exit tie breakers early in unique or no match case (#1130)
Tie breakers for Autofill fields should only be evaluated if there is a need to, in particular not if only a single or no field is matched. Apart from a potential minor performance improvement, this should not cause any user-visible changes, but does simplify the log output considerably.
Diffstat (limited to 'autofill-parser')
-rw-r--r--autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategyDsl.kt12
1 files changed, 10 insertions, 2 deletions
diff --git a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategyDsl.kt b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategyDsl.kt
index 86201be8..f3f6d97d 100644
--- a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategyDsl.kt
+++ b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategyDsl.kt
@@ -94,6 +94,10 @@ class SingleFieldMatcher(
override fun match(fields: List<FormField>, alreadyMatched: List<FormField>): List<FormField>? {
return fields.minus(alreadyMatched).filter { take(it, alreadyMatched) }.let { contestants ->
+ when (contestants.size) {
+ 1 -> return@let listOf(contestants.single())
+ 0 -> return@let null
+ }
var current = contestants
for ((i, tieBreaker) in tieBreakers.withIndex()) {
// Successively filter matched fields via tie breakers...
@@ -127,11 +131,15 @@ private class PairOfFieldsMatcher(
return fields.minus(alreadyMatched).zipWithNext()
.filter { it.first directlyPrecedes it.second }.filter { take(it, alreadyMatched) }
.let { contestants ->
+ when (contestants.size) {
+ 1 -> return@let contestants.single().toList()
+ 0 -> return@let null
+ }
var current = contestants
for ((i, tieBreaker) in tieBreakers.withIndex()) {
val new = current.filter { tieBreaker(it, alreadyMatched) }
if (new.isEmpty()) {
- d { "Tie breaker #${i + 1}: Didn't match any field; skipping" }
+ d { "Tie breaker #${i + 1}: Didn't match any pair of fields; skipping" }
continue
}
// and return if the available options have been narrowed to a single field.
@@ -140,7 +148,7 @@ private class PairOfFieldsMatcher(
current = new
break
}
- d { "Tie breaker #${i + 1}: Matched ${new.size} fields; continuing" }
+ d { "Tie breaker #${i + 1}: Matched ${new.size} pairs of fields; continuing" }
current = new
}
current.singleOrNull()?.toList()