reference: remove remaining uses of "expression()"

The remaining uses of "expression()" were quite trivial; probably goes without
saying, but just using string-concatenating for these is more performant as well,
and removing the extra abstraction may make it easier to read;

    pkg: github.com/distribution/distribution/v3/reference
    BenchmarkExpression
    BenchmarkExpression-10    27260877        43.10 ns/op      24 B/op       1 allocs/op
    BenchmarkConcat
    BenchmarkConcat-10      1000000000         0.3154 ns/op     0 B/op       0 allocs/op
    PASS
    ok  	github.com/distribution/distribution/v3/reference	1.762s

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-11-09 19:12:51 +01:00
parent 04d6592df1
commit f0c7c97e73
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -55,7 +55,7 @@ var (
// that may be part of image names. This is purposely a subset of what is // that may be part of image names. This is purposely a subset of what is
// allowed by DNS to ensure backwards compatibility with Docker image // allowed by DNS to ensure backwards compatibility with Docker image
// names. This includes IPv4 addresses on decimal format. // names. This includes IPv4 addresses on decimal format.
domainName = expression(domainNameComponent, optional(repeated(`\.`+domainNameComponent))) domainName = domainNameComponent + optional(repeated(`\.`+domainNameComponent))
// host defines the structure of potential domains based on the URI // host defines the structure of potential domains based on the URI
// Host subcomponent on rfc3986. It may be a subset of DNS domain name, // Host subcomponent on rfc3986. It may be a subset of DNS domain name,
@ -66,7 +66,7 @@ var (
// allowed by the URI Host subcomponent on rfc3986 to ensure backwards // allowed by the URI Host subcomponent on rfc3986 to ensure backwards
// compatibility with Docker image names. // compatibility with Docker image names.
domain = expression(host, optional(`:[0-9]+`)) domain = host + optional(`:[0-9]+`)
// DomainRegexp matches hostname or IP-addresses, optionally including a port // DomainRegexp matches hostname or IP-addresses, optionally including a port
// number. It defines the structure of potential domain components that may be // number. It defines the structure of potential domain components that may be
@ -96,8 +96,8 @@ var (
// pathComponent restricts path-components to start with an alphanumeric // pathComponent restricts path-components to start with an alphanumeric
// character, with following parts able to be separated by a separator // character, with following parts able to be separated by a separator
// (one period, one or two underscore and multiple dashes). // (one period, one or two underscore and multiple dashes).
pathComponent = expression(alphanumeric, optional(repeated(separator, alphanumeric))) pathComponent = alphanumeric + optional(repeated(separator, alphanumeric))
namePat = expression(optional(domain+`/`), pathComponent, optional(repeated(`/`+pathComponent))) namePat = optional(domain+`/`) + pathComponent + optional(repeated(`/`+pathComponent))
// NameRegexp is the format for the name component of references, including // NameRegexp is the format for the name component of references, including
// an optional domain and port, but without tag or digest suffix. // an optional domain and port, but without tag or digest suffix.
@ -124,12 +124,6 @@ var (
anchoredIdentifierRegexp = regexp.MustCompile(anchored(identifier)) anchoredIdentifierRegexp = regexp.MustCompile(anchored(identifier))
) )
// expression defines a full expression, where each regular expression must
// follow the previous.
func expression(res ...string) string {
return strings.Join(res, "")
}
// optional wraps the expression in a non-capturing group and makes the // optional wraps the expression in a non-capturing group and makes the
// production optional. // production optional.
func optional(res ...string) string { func optional(res ...string) string {