Skip to content

Commit

Permalink
[tagger/entity_id] Replace SplitN with Index to avoid unnecessary all…
Browse files Browse the repository at this point in the history
…ocations (#29625)
  • Loading branch information
davidor authored Sep 27, 2024
1 parent 6d5f968 commit bcd3df0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions comp/core/tagger/types/entity_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,32 @@ 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
func (de defaultEntityID) String() string {
return string(de)
}

func newDefaultEntityID(id string) EntityID {
func newDefaultEntityID(id string) defaultEntityID {
return defaultEntityID(id)
}

Expand Down

0 comments on commit bcd3df0

Please sign in to comment.