Skip to content

Commit 3e1b991

Browse files
committed
optimize internal set
1 parent 396046c commit 3e1b991

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

migration/cmd_option.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ func newCLIOption() *cliOption {
1414
return &cliOption{
1515
root: "",
1616
create: false,
17-
stages: &optionSet{elements: make(map[string]struct{})},
18-
refreshes: &optionSet{elements: make(map[string]struct{})},
19-
only: &optionSet{elements: make(map[string]struct{})},
20-
exclude: &optionSet{elements: make(map[string]struct{})},
17+
stages: &optionSet{elements: make([]string, 0)},
18+
refreshes: &optionSet{elements: make([]string, 0)},
19+
only: &optionSet{elements: make([]string, 0)},
20+
exclude: &optionSet{elements: make([]string, 0)},
2121
}
2222
}
2323

migration/migration_option.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ type migrationOption struct {
77

88
func newOption() *migrationOption {
99
return &migrationOption{
10-
only: &optionSet{elements: make(map[string]struct{})},
11-
exclude: &optionSet{elements: make(map[string]struct{})},
10+
only: &optionSet{elements: make([]string, 0)},
11+
exclude: &optionSet{elements: make([]string, 0)},
1212
}
1313
}
1414

migration/utils.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ package migration
33
import (
44
"path/filepath"
55
"regexp"
6+
"slices"
67
"strings"
78

89
"github.com/spf13/cobra"
910
)
1011

1112
type optionSet struct {
12-
elements map[string]struct{}
13+
elements []string
1314
}
1415

1516
func (s *optionSet) Add(elements ...string) {
1617
for _, element := range elements {
17-
s.elements[element] = struct{}{}
18+
if !slices.Contains(s.elements, element) {
19+
s.elements = append(s.elements, element)
20+
}
1821
}
1922
}
2023

@@ -23,11 +26,7 @@ func (s *optionSet) Size() int {
2326
}
2427

2528
func (s *optionSet) Elements() []string {
26-
keys := make([]string, 0, len(s.elements))
27-
for key := range s.elements {
28-
keys = append(keys, key)
29-
}
30-
return keys
29+
return append([]string{}, s.elements...)
3130
}
3231

3332
// normalizePath join and normalize file path.

0 commit comments

Comments
 (0)