From ce0d0f5dbed4c7623cd3a29bfc53335cb087d87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B3=E6=98=8E?= Date: Mon, 19 Feb 2024 16:50:30 +0800 Subject: [PATCH] Refactor Contains function to improve performance by using index iteration over collection --- intersect.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/intersect.go b/intersect.go index cf6cab3d..520752b3 100644 --- a/intersect.go +++ b/intersect.go @@ -2,8 +2,8 @@ package lo // Contains returns true if an element is present in a collection. func Contains[T comparable](collection []T, element T) bool { - for _, item := range collection { - if item == element { + for i := range collection { + if collection[i] == element { return true } }