summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-02-12 22:42:31 -0800
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2025-02-12 22:42:31 -0800
commitd622527f714f6423323c26a722e43f71dc4a4c63 (patch)
treef80ecb02b3a8c0e1e2008d059537fe0bfd9579c3
parent9826fd35bc1ac81016e4b8c4567ff39cfaf34996 (diff)
parent687b5abaf57276dd11e8e8346312a7bfc2760895 (diff)
Merge "Optimize HasIntersection" into main
-rw-r--r--android/util.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/android/util.go b/android/util.go
index e8d9301dd..2673a3a18 100644
--- a/android/util.go
+++ b/android/util.go
@@ -238,8 +238,13 @@ func ListSetDifference[T comparable](l1, l2 []T) (bool, []T, []T) {
// Returns true if the two lists have common elements.
func HasIntersection[T comparable](l1, l2 []T) bool {
- _, a, b := ListSetDifference(l1, l2)
- return len(a)+len(b) < len(setFromList(l1))+len(setFromList(l2))
+ m1 := setFromList(l1)
+ for _, x := range l2 {
+ if _, ok := m1[x]; ok {
+ return true
+ }
+ }
+ return false
}
// Returns true if the given string s is prefixed with any string in the given prefix list.