Skip to content

Commit 6e04ee5

Browse files
committed
Optimize map field description parsing
1 parent bc7d4b0 commit 6e04ee5

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

‎cli/completer.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,24 +225,24 @@ func pluralizeNoun(noun string) string {
225225
}
226226
}
227227

228+
var mapFieldDescriptionPattern = regexp.MustCompile(`([A-Za-z0-9_-]+\[\d+\]\.[A-Za-z0-9_.:-]+)=`)
229+
228230
func mapFieldsFromDescription(description string) []string {
229231
fields := []string{}
230-
seen := make(map[string]bool)
231-
232-
re := regexp.MustCompile(`([A-Za-z0-9_-]+\[\d+\]\.[A-Za-z0-9_.:-]+)=`)
232+
seen := make(map[string]struct{})
233233

234-
matches := re.FindAllStringSubmatch(description, -1)
234+
matches := mapFieldDescriptionPattern.FindAllStringSubmatch(description, -1)
235235
for _, match := range matches {
236236
if len(match) < 2 {
237237
continue
238238
}
239239

240240
field := match[1] + "="
241-
if seen[field] {
241+
if _, exists := seen[field]; exists {
242242
continue
243243
}
244244

245-
seen[field] = true
245+
seen[field] = struct{}{}
246246
fields = append(fields, field)
247247
}
248248

0 commit comments

Comments
 (0)