diff --git a/acl/bench_test.go b/acl/bench_test.go index 54ec186b..f0ddd293 100644 --- a/acl/bench_test.go +++ b/acl/bench_test.go @@ -12,18 +12,17 @@ func BenchmarkTable_ToGRPCMessage(b *testing.B) { const size = 4 tb := new(acl.Table) - rs := make([]*acl.Record, size) + rs := make([]acl.Record, size) for i := range rs { - fs := make([]*acl.HeaderFilter, size) + fs := make([]acl.HeaderFilter, size) for j := range fs { - fs[j] = acltest.GenerateFilter(false) + fs[j] = *acltest.GenerateFilter(false) } - ts := make([]*acl.Target, size) + ts := make([]acl.Target, size) for j := range ts { - ts[j] = acltest.GenerateTarget(false) + ts[j] = *acltest.GenerateTarget(false) } - rs[i] = new(acl.Record) rs[i].SetFilters(fs) rs[i].SetTargets(ts) } diff --git a/acl/convert.go b/acl/convert.go index 55b333af..a49aa6be 100644 --- a/acl/convert.go +++ b/acl/convert.go @@ -185,7 +185,7 @@ func (f *HeaderFilter) FromGRPCMessage(m grpc.Message) error { return nil } -func HeaderFiltersToGRPC(fs []*HeaderFilter) (res []*acl.EACLRecord_Filter) { +func HeaderFiltersToGRPC(fs []HeaderFilter) (res []*acl.EACLRecord_Filter) { if fs != nil { res = make([]*acl.EACLRecord_Filter, 0, len(fs)) @@ -197,23 +197,17 @@ func HeaderFiltersToGRPC(fs []*HeaderFilter) (res []*acl.EACLRecord_Filter) { return } -func HeaderFiltersFromGRPC(fs []*acl.EACLRecord_Filter) (res []*HeaderFilter, err error) { +func HeaderFiltersFromGRPC(fs []*acl.EACLRecord_Filter) (res []HeaderFilter, err error) { if fs != nil { - res = make([]*HeaderFilter, 0, len(fs)) + res = make([]HeaderFilter, len(fs)) for i := range fs { - var x *HeaderFilter - if fs[i] != nil { - x = new(HeaderFilter) - - err = x.FromGRPCMessage(fs[i]) + err = res[i].FromGRPCMessage(fs[i]) if err != nil { return } } - - res = append(res, x) } } @@ -245,7 +239,7 @@ func (t *Target) FromGRPCMessage(m grpc.Message) error { return nil } -func TargetsToGRPC(ts []*Target) (res []*acl.EACLRecord_Target) { +func TargetsToGRPC(ts []Target) (res []*acl.EACLRecord_Target) { if ts != nil { res = make([]*acl.EACLRecord_Target, 0, len(ts)) @@ -257,23 +251,17 @@ func TargetsToGRPC(ts []*Target) (res []*acl.EACLRecord_Target) { return } -func TargetsFromGRPC(fs []*acl.EACLRecord_Target) (res []*Target, err error) { +func TargetsFromGRPC(fs []*acl.EACLRecord_Target) (res []Target, err error) { if fs != nil { - res = make([]*Target, 0, len(fs)) + res = make([]Target, len(fs)) for i := range fs { - var x *Target - if fs[i] != nil { - x = new(Target) - - err = x.FromGRPCMessage(fs[i]) + err = res[i].FromGRPCMessage(fs[i]) if err != nil { return } } - - res = append(res, x) } } @@ -319,7 +307,7 @@ func (r *Record) FromGRPCMessage(m grpc.Message) error { return nil } -func RecordsToGRPC(ts []*Record) (res []*acl.EACLRecord) { +func RecordsToGRPC(ts []Record) (res []*acl.EACLRecord) { if ts != nil { res = make([]*acl.EACLRecord, 0, len(ts)) @@ -331,23 +319,17 @@ func RecordsToGRPC(ts []*Record) (res []*acl.EACLRecord) { return } -func RecordsFromGRPC(fs []*acl.EACLRecord) (res []*Record, err error) { +func RecordsFromGRPC(fs []*acl.EACLRecord) (res []Record, err error) { if fs != nil { - res = make([]*Record, 0, len(fs)) + res = make([]Record, len(fs)) for i := range fs { - var x *Record - if fs[i] != nil { - x = new(Record) - - err = x.FromGRPCMessage(fs[i]) + err = res[i].FromGRPCMessage(fs[i]) if err != nil { return } } - - res = append(res, x) } } diff --git a/acl/marshal.go b/acl/marshal.go index cfa4470a..5ef3676f 100644 --- a/acl/marshal.go +++ b/acl/marshal.go @@ -67,7 +67,7 @@ func (t *Table) StableMarshal(buf []byte) ([]byte, error) { offset += n for i := range t.records { - n, err = protoutil.NestedStructureMarshal(tableRecordsField, buf[offset:], t.records[i]) + n, err = protoutil.NestedStructureMarshal(tableRecordsField, buf[offset:], &t.records[i]) if err != nil { return nil, err } @@ -88,7 +88,7 @@ func (t *Table) StableSize() (size int) { size += protoutil.NestedStructureSize(tableContainerIDField, t.cid) for i := range t.records { - size += protoutil.NestedStructureSize(tableRecordsField, t.records[i]) + size += protoutil.NestedStructureSize(tableRecordsField, &t.records[i]) } return size @@ -129,7 +129,7 @@ func (r *Record) StableMarshal(buf []byte) ([]byte, error) { offset += n for i := range r.filters { - n, err = protoutil.NestedStructureMarshal(recordFiltersField, buf[offset:], r.filters[i]) + n, err = protoutil.NestedStructureMarshal(recordFiltersField, buf[offset:], &r.filters[i]) if err != nil { return nil, err } @@ -138,7 +138,7 @@ func (r *Record) StableMarshal(buf []byte) ([]byte, error) { } for i := range r.targets { - n, err = protoutil.NestedStructureMarshal(recordTargetsField, buf[offset:], r.targets[i]) + n, err = protoutil.NestedStructureMarshal(recordTargetsField, buf[offset:], &r.targets[i]) if err != nil { return nil, err } @@ -159,11 +159,11 @@ func (r *Record) StableSize() (size int) { size += protoutil.EnumSize(recordActionField, int32(r.action)) for i := range r.filters { - size += protoutil.NestedStructureSize(recordFiltersField, r.filters[i]) + size += protoutil.NestedStructureSize(recordFiltersField, &r.filters[i]) } for i := range r.targets { - size += protoutil.NestedStructureSize(recordTargetsField, r.targets[i]) + size += protoutil.NestedStructureSize(recordTargetsField, &r.targets[i]) } return size diff --git a/acl/test/generate.go b/acl/test/generate.go index 0f72119d..3d90fc91 100644 --- a/acl/test/generate.go +++ b/acl/test/generate.go @@ -42,13 +42,13 @@ func GenerateTable(empty bool) *acl.Table { return m } -func GenerateRecords(empty bool) []*acl.Record { - var rs []*acl.Record +func GenerateRecords(empty bool) []acl.Record { + var rs []acl.Record if !empty { rs = append(rs, - GenerateRecord(false), - GenerateRecord(false), + *GenerateRecord(false), + *GenerateRecord(false), ) } @@ -68,13 +68,13 @@ func GenerateRecord(empty bool) *acl.Record { return m } -func GenerateFilters(empty bool) []*acl.HeaderFilter { - var fs []*acl.HeaderFilter +func GenerateFilters(empty bool) []acl.HeaderFilter { + var fs []acl.HeaderFilter if !empty { fs = append(fs, - GenerateFilter(false), - GenerateFilter(false), + *GenerateFilter(false), + *GenerateFilter(false), ) } @@ -94,13 +94,13 @@ func GenerateFilter(empty bool) *acl.HeaderFilter { return m } -func GenerateTargets(empty bool) []*acl.Target { - var ts []*acl.Target +func GenerateTargets(empty bool) []acl.Target { + var ts []acl.Target if !empty { ts = append(ts, - GenerateTarget(false), - GenerateTarget(false), + *GenerateTarget(false), + *GenerateTarget(false), ) } diff --git a/acl/types.go b/acl/types.go index 58b310d1..70994b4d 100644 --- a/acl/types.go +++ b/acl/types.go @@ -27,9 +27,9 @@ type Record struct { action Action - filters []*HeaderFilter + filters []HeaderFilter - targets []*Target + targets []Target } // Table is a unified structure of EACLTable @@ -39,7 +39,7 @@ type Table struct { cid *refs.ContainerID - records []*Record + records []Record } type TokenLifetime struct { @@ -224,7 +224,7 @@ func (r *Record) SetAction(v Action) { } } -func (r *Record) GetFilters() []*HeaderFilter { +func (r *Record) GetFilters() []HeaderFilter { if r != nil { return r.filters } @@ -232,13 +232,13 @@ func (r *Record) GetFilters() []*HeaderFilter { return nil } -func (r *Record) SetFilters(v []*HeaderFilter) { +func (r *Record) SetFilters(v []HeaderFilter) { if r != nil { r.filters = v } } -func (r *Record) GetTargets() []*Target { +func (r *Record) GetTargets() []Target { if r != nil { return r.targets } @@ -246,7 +246,7 @@ func (r *Record) GetTargets() []*Target { return nil } -func (r *Record) SetTargets(v []*Target) { +func (r *Record) SetTargets(v []Target) { if r != nil { r.targets = v } @@ -280,7 +280,7 @@ func (t *Table) SetContainerID(v *refs.ContainerID) { } } -func (t *Table) GetRecords() []*Record { +func (t *Table) GetRecords() []Record { if t != nil { return t.records } @@ -288,7 +288,7 @@ func (t *Table) GetRecords() []*Record { return nil } -func (t *Table) SetRecords(v []*Record) { +func (t *Table) SetRecords(v []Record) { if t != nil { t.records = v }