Skip to content

net/http: remoteEmptyPort could be optimized #76651

@dxasu

Description

@dxasu

func removeEmptyPort(host string) string {

func removeEmptyPort(host string) string {
	if hasPort(host) {
		return strings.TrimSuffix(host, ":")
	}
	return host
}

can be optimized to:

func removeEmptyPort(host string) string {
	if len(host) > 0 && host[len(host)-1] == ':' {
		return host[:len(host)-1]
	}
	return host
}

or using strings.HasSuffix:

func removeEmptyPort(host string) string {
	if hasPort(host) && strings.HasSuffix(host, ":") {
		return strings.TrimSuffix(host, ":")
	}
	return host
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.ImplementationIssues describing a semantics-preserving change to the Go implementation.Performance

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions