From 7726e27f3b79e031fe9a9ea9504dea5df0327e02 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 11 Apr 2023 00:39:25 -0600 Subject: maps: Get HaveAnyKeysInCommon to be inlinable --- lib/maps/maputil.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/maps') 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 -- cgit v1.2.3-2-g168b