mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-06 03:13:48 +02:00
37e3fdee55
We can use `(*regexp.Regexp).MatchString` instead of `(*regexp.Regexp).Match([]byte(...))` to avoid unnecessary `[]byte` conversions and reduce allocations. A one-line change for free performance gain. Benchmark: ```go func BenchmarkMatch(b *testing.B) { for i := 0; i < b.N; i++ { if match := envOnlyRe.Match([]byte("{{ .Env.FOO }}")); !match { b.Fail() } } } func BenchmarkMatchString(b *testing.B) { for i := 0; i < b.N; i++ { if match := envOnlyRe.MatchString("{{ .Env.FOO }}"); !match { b.Fail() } } } ``` Result: ``` goos: linux goarch: amd64 pkg: github.com/goreleaser/goreleaser/internal/tmpl cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics BenchmarkMatch-16 4320873 381.2 ns/op 16 B/op 1 allocs/op BenchmarkMatchString-16 5973543 203.9 ns/op 0 B/op 0 allocs/op PASS ok github.com/goreleaser/goreleaser/internal/tmpl 3.366s ``` Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> |
||
---|---|---|
.. | ||
archivefiles | ||
artifact | ||
builders | ||
client | ||
commitauthor | ||
deprecate | ||
exec | ||
extrafiles | ||
gio | ||
git | ||
golden | ||
http | ||
ids | ||
logext | ||
middleware | ||
pipe | ||
pipeline | ||
semerrgroup | ||
shell | ||
skips | ||
static | ||
testctx | ||
testlib | ||
tmpl | ||
yaml |