From 485732aa8f250f19f9929226bbdf8d06ba43f900 Mon Sep 17 00:00:00 2001 From: fujiwara Date: Tue, 17 Sep 2024 15:19:37 +0900 Subject: [PATCH] simplify goos: linux goarch: amd64 pkg: github.com/fujiwara/tfstate-lookup/tfstate cpu: AMD Ryzen 5 3400G with Radeon Vega Graphics BenchmarkLookupFile-8 7789 143841 ns/op 89158 B/op 854 allocs/op PASS --- tfstate/lookup.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tfstate/lookup.go b/tfstate/lookup.go index 678aca0..c9dc279 100644 --- a/tfstate/lookup.go +++ b/tfstate/lookup.go @@ -253,18 +253,13 @@ func quoteJQQuery(query string) string { return query } parts := quoteSplitRegex.Split(query, -1) - parts_coalesced := make([]string, 0, len(parts)) - - for _, part := range parts { - if part != "" { - parts_coalesced = append(parts_coalesced, part) - } - } - var builder strings.Builder + builder.Grow(len(query) + 5*len(parts)) builder.WriteByte('.') - - for _, part := range parts_coalesced { + for _, part := range parts { + if part == "" { + continue + } builder.WriteByte('[') if quoteIndexRegex.MatchString(part) { builder.WriteString(part) @@ -272,9 +267,7 @@ func quoteJQQuery(query string) string { if !strings.HasPrefix(part, `"`) { builder.WriteByte('"') } - builder.WriteString(part) - if !strings.HasSuffix(part, `"`) { builder.WriteByte('"') }