From a966a64cc60d3817e773a2f4eba7536b17376675 Mon Sep 17 00:00:00 2001 From: guanming Date: Fri, 28 Jun 2024 07:04:51 +0800 Subject: [PATCH] Refactor Contains function to improve performance by using index iteration over collection (#428) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 关明 --- 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 } }