Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tagger/entity_id] Replace SplitN with Index to avoid unnecessary allocations #29625

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading