Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fujiwara committed Sep 17, 2024
1 parent 2ceb58a commit 485732a
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions tfstate/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,28 +253,21 @@ 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)
} else {
if !strings.HasPrefix(part, `"`) {
builder.WriteByte('"')
}

builder.WriteString(part)

if !strings.HasSuffix(part, `"`) {
builder.WriteByte('"')
}
Expand Down

0 comments on commit 485732a

Please sign in to comment.