aboutsummaryrefslogtreecommitdiff
path: root/int_slice.go
diff options
context:
space:
mode:
authorEric Paris <[email protected]>2015-08-12 10:19:24 -0500
committerEric Paris <[email protected]>2015-08-12 10:19:24 -0500
commit4869ec2ae0628354eaac5bf88fccf9a7265ae475 (patch)
treea512d39ec0822c7a5ff3b0960b0b16894f2df007 /int_slice.go
parent978c009ee41c0f14bd0c0e2927ae81713cc65864 (diff)
parent95a6a40798df11df014298af8a8250af515fa753 (diff)
Merge pull request #41 from eparis/fix-slice-defaults
Do not append to default values in {String,Int}Slice
Diffstat (limited to 'int_slice.go')
-rw-r--r--int_slice.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/int_slice.go b/int_slice.go
index b28353d..7c6ed79 100644
--- a/int_slice.go
+++ b/int_slice.go
@@ -7,11 +7,16 @@ import (
)
// -- intSlice Value
-type intSliceValue []int
+type intSliceValue struct {
+ value *[]int
+ changed bool
+}
func newIntSliceValue(val []int, p *[]int) *intSliceValue {
- *p = val
- return (*intSliceValue)(p)
+ isv := new(intSliceValue)
+ isv.value = p
+ *isv.value = val
+ return isv
}
func (s *intSliceValue) Set(val string) error {
@@ -25,7 +30,12 @@ func (s *intSliceValue) Set(val string) error {
}
}
- *s = append(*s, out...)
+ if !s.changed {
+ *s.value = out
+ } else {
+ *s.value = append(*s.value, out...)
+ }
+ s.changed = true
return nil
}
@@ -34,8 +44,8 @@ func (s *intSliceValue) Type() string {
}
func (s *intSliceValue) String() string {
- out := make([]string, len(*s))
- for i, d := range *s {
+ out := make([]string, len(*s.value))
+ for i, d := range *s.value {
out[i] = fmt.Sprintf("%d", d)
}
return "[" + strings.Join(out, ",") + "]"