summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Cole Faust <colefaust@google.com> 2025-02-12 21:04:09 -0800
committer Cole Faust <colefaust@google.com> 2025-02-12 21:04:09 -0800
commit687b5abaf57276dd11e8e8346312a7bfc2760895 (patch)
tree0fdf8feb915f73ac692b648f432a72e960710b6a
parentdc170e72fad31a5cef8e3427773d7f9d323c03f9 (diff)
Optimize HasIntersection
Just noticed it was wildly unoptimized while making a different change. Test: m nothing --no-skip-soong-tests Change-Id: I319a1f5ebc1269c5949735e77ec3bd8ef6ee95ee
-rw-r--r--android/util.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/android/util.go b/android/util.go
index 30d8ec6b3..b9ab77aec 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.