From dce6002d2516d8a208d96986bfe51dfc10c7de3c Mon Sep 17 00:00:00 2001 From: joshmeranda Date: Mon, 25 Nov 2024 13:13:46 -0500 Subject: [PATCH] use slices pkg to search for candidates --- types/schemas.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/types/schemas.go b/types/schemas.go index c2e153c5..ac1f7e89 100644 --- a/types/schemas.go +++ b/types/schemas.go @@ -141,11 +141,12 @@ func (s *Schemas) doAddSchema(schema Schema, replace bool) *Schemas { schemas[schema.ID] = &schema if replace { - for i, candidate := range s.schemas { - if candidate.ID == schema.ID { - s.schemas[i] = &schema - break - } + i := slices.IndexFunc(s.schemas, func(candidate *Schema) bool { + return candidate.ID == schema.ID + }) + + if i >= 0 { + s.schemas[i] = &schema } } else { s.schemas = append(s.schemas, &schema)