Optimize HasIntersection
Just noticed it was wildly unoptimized while making
a different change.
Test: m nothing --no-skip-soong-tests
Change-Id: I319a1f5ebc1269c5949735e77ec3bd8ef6ee95ee
diff --git a/android/util.go b/android/util.go
index 30d8ec6..b9ab77a 100644
--- a/android/util.go
+++ b/android/util.go
@@ -238,8 +238,13 @@
// 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.