diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-11 00:39:25 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-13 13:18:18 -0600 |
commit | 7726e27f3b79e031fe9a9ea9504dea5df0327e02 (patch) | |
tree | 631f9de458b9b91b02fe07e2a812233a3ac20520 | |
parent | f4d10a92abc46bf0156ff1b475304471c16405da (diff) |
maps: Get HaveAnyKeysInCommon to be inlinable
-rw-r--r-- | lib/maps/maputil.go | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/maps/maputil.go b/lib/maps/maputil.go index 63e52a0..3b6691a 100644 --- a/lib/maps/maputil.go +++ b/lib/maps/maputil.go @@ -31,13 +31,20 @@ func HasKey[K comparable, V any](m map[K]V, k K) bool { return has } -func HaveAnyKeysInCommon[K comparable, V1, V2 any](small map[K]V1, big map[K]V2) bool { - if len(big) < len(small) { - return HaveAnyKeysInCommon(big, small) - } - for v := range small { - if _, ok := big[v]; ok { - return true +func HaveAnyKeysInCommon[K comparable, V1, V2 any](a map[K]V1, b map[K]V2) bool { + if len(a) < len(b) { + small, big := a, b + for v := range small { + if _, ok := big[v]; ok { + return true + } + } + } else { + small, big := b, a + for v := range small { + if _, ok := big[v]; ok { + return true + } } } return false |