Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: code optimization #378

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions duration_slice.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pflag

import (
"fmt"
"strings"
"time"
)
Expand Down Expand Up @@ -46,7 +45,7 @@ func (s *durationSliceValue) Type() string {
func (s *durationSliceValue) String() string {
out := make([]string, len(*s.value))
for i, d := range *s.value {
out[i] = fmt.Sprintf("%s", d)
out[i] =d.String()
}
return "[" + strings.Join(out, ",") + "]"
}
Expand All @@ -56,7 +55,7 @@ func (s *durationSliceValue) fromString(val string) (time.Duration, error) {
}

func (s *durationSliceValue) toString(val time.Duration) string {
return fmt.Sprintf("%s", val)
return val.String()
}

func (s *durationSliceValue) Append(val string) error {
Expand Down
5 changes: 1 addition & 4 deletions ipnet_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ func getCIDR(ip net.IP, cidr *net.IPNet, err error) net.IPNet {
}

func equalCIDR(c1 net.IPNet, c2 net.IPNet) bool {
if c1.String() == c2.String() {
return true
}
return false
return c1.String() == c2.String()
}

func setUpIPNetFlagSet(ipsp *[]net.IPNet) *FlagSet {
Expand Down
8 changes: 2 additions & 6 deletions string_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@ func (s *stringArrayValue) Append(val string) error {

func (s *stringArrayValue) Replace(val []string) error {
out := make([]string, len(val))
for i, d := range val {
out[i] = d
}
copy(out, val)
*s.value = out
return nil
}

func (s *stringArrayValue) GetSlice() []string {
out := make([]string, len(*s.value))
for i, d := range *s.value {
out[i] = d
}
copy(out, *s.value)
return out
}

Expand Down