From bcd3df05ce61d6382871c2ce57e2f4c2eebf011c Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Fri, 27 Sep 2024 17:59:02 +0200 Subject: [PATCH] [tagger/entity_id] Replace SplitN with Index to avoid unnecessary allocations (#29625) --- comp/core/tagger/types/entity_id.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/comp/core/tagger/types/entity_id.go b/comp/core/tagger/types/entity_id.go index e049d2825c799..c7ec064776d92 100644 --- a/comp/core/tagger/types/entity_id.go +++ b/comp/core/tagger/types/entity_id.go @@ -31,24 +31,24 @@ type defaultEntityID string // GetID implements EntityID#GetID func (de defaultEntityID) GetID() string { - parts := strings.SplitN(string(de), separator, 2) + separatorIndex := strings.Index(string(de), separator) - if len(parts) != 2 { + if separatorIndex == -1 { return "" } - return parts[1] + return string(de[separatorIndex+len(separator):]) } // GetPrefix implements EntityID#GetPrefix func (de defaultEntityID) GetPrefix() EntityIDPrefix { - parts := strings.SplitN(string(de), separator, 2) + separatorIndex := strings.Index(string(de), separator) - if len(parts) != 2 { + if separatorIndex == -1 { return "" } - return EntityIDPrefix(parts[0]) + return EntityIDPrefix(de[:separatorIndex]) } // String implements EntityID#String @@ -56,7 +56,7 @@ func (de defaultEntityID) String() string { return string(de) } -func newDefaultEntityID(id string) EntityID { +func newDefaultEntityID(id string) defaultEntityID { return defaultEntityID(id) }