[#376] object: Remove pointer from slices

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-03-02 11:03:56 +03:00 committed by Alex Vanin
parent e21a7823c5
commit aa1e092ca5
4 changed files with 26 additions and 38 deletions

View file

@ -1443,7 +1443,7 @@ func (f *SearchFilter) FromGRPCMessage(m grpc.Message) error {
return nil
}
func SearchFiltersToGRPC(fs []*SearchFilter) (res []*object.SearchRequest_Body_Filter) {
func SearchFiltersToGRPC(fs []SearchFilter) (res []*object.SearchRequest_Body_Filter) {
if fs != nil {
res = make([]*object.SearchRequest_Body_Filter, 0, len(fs))
@ -1455,23 +1455,17 @@ func SearchFiltersToGRPC(fs []*SearchFilter) (res []*object.SearchRequest_Body_F
return
}
func SearchFiltersFromGRPC(fs []*object.SearchRequest_Body_Filter) (res []*SearchFilter, err error) {
func SearchFiltersFromGRPC(fs []*object.SearchRequest_Body_Filter) (res []SearchFilter, err error) {
if fs != nil {
res = make([]*SearchFilter, 0, len(fs))
res = make([]SearchFilter, len(fs))
for i := range fs {
var x *SearchFilter
if fs[i] != nil {
x = new(SearchFilter)
err = x.FromGRPCMessage(fs[i])
err = res[i].FromGRPCMessage(fs[i])
if err != nil {
return
}
}
res = append(res, x)
}
}
@ -1650,7 +1644,7 @@ func (r *Range) FromGRPCMessage(m grpc.Message) error {
return nil
}
func RangesToGRPC(rs []*Range) (res []*object.Range) {
func RangesToGRPC(rs []Range) (res []*object.Range) {
if rs != nil {
res = make([]*object.Range, 0, len(rs))
@ -1662,23 +1656,17 @@ func RangesToGRPC(rs []*Range) (res []*object.Range) {
return
}
func RangesFromGRPC(rs []*object.Range) (res []*Range, err error) {
func RangesFromGRPC(rs []*object.Range) (res []Range, err error) {
if rs != nil {
res = make([]*Range, 0, len(rs))
res = make([]Range, len(rs))
for i := range rs {
var r *Range
if rs[i] != nil {
r = new(Range)
err = r.FromGRPCMessage(rs[i])
err = res[i].FromGRPCMessage(rs[i])
if err != nil {
return
}
}
res = append(res, r)
}
}

View file

@ -1158,7 +1158,7 @@ func (r *SearchRequestBody) StableMarshal(buf []byte) ([]byte, error) {
offset += n
for i := range r.filters {
n, err = proto.NestedStructureMarshal(searchReqBodyFiltersField, buf[offset:], r.filters[i])
n, err = proto.NestedStructureMarshal(searchReqBodyFiltersField, buf[offset:], &r.filters[i])
if err != nil {
return nil, err
}
@ -1178,7 +1178,7 @@ func (r *SearchRequestBody) StableSize() (size int) {
size += proto.UInt32Size(searchReqBodyVersionField, r.version)
for i := range r.filters {
size += proto.NestedStructureSize(searchReqBodyFiltersField, r.filters[i])
size += proto.NestedStructureSize(searchReqBodyFiltersField, &r.filters[i])
}
return size
@ -1400,7 +1400,7 @@ func (r *GetRangeHashRequestBody) StableMarshal(buf []byte) ([]byte, error) {
offset += n
for i := range r.rngs {
n, err = proto.NestedStructureMarshal(getRangeHashReqBodyRangesField, buf[offset:], r.rngs[i])
n, err = proto.NestedStructureMarshal(getRangeHashReqBodyRangesField, buf[offset:], &r.rngs[i])
if err != nil {
return nil, err
}
@ -1431,7 +1431,7 @@ func (r *GetRangeHashRequestBody) StableSize() (size int) {
size += proto.NestedStructureSize(getRangeHashReqBodyAddressField, r.addr)
for i := range r.rngs {
size += proto.NestedStructureSize(getRangeHashReqBodyRangesField, r.rngs[i])
size += proto.NestedStructureSize(getRangeHashReqBodyRangesField, &r.rngs[i])
}
size += proto.BytesSize(getRangeHashReqBodySaltField, r.salt)

View file

@ -380,13 +380,13 @@ func GenerateSearchFilter(empty bool) *object.SearchFilter {
return m
}
func GenerateSearchFilters(empty bool) []*object.SearchFilter {
var res []*object.SearchFilter
func GenerateSearchFilters(empty bool) []object.SearchFilter {
var res []object.SearchFilter
if !empty {
res = append(res,
GenerateSearchFilter(false),
GenerateSearchFilter(false),
*GenerateSearchFilter(false),
*GenerateSearchFilter(false),
)
}
@ -452,13 +452,13 @@ func GenerateRange(empty bool) *object.Range {
return m
}
func GenerateRanges(empty bool) []*object.Range {
var res []*object.Range
func GenerateRanges(empty bool) []object.Range {
var res []object.Range
if !empty {
res = append(res,
GenerateRange(false),
GenerateRange(false),
*GenerateRange(false),
*GenerateRange(false),
)
}

View file

@ -218,7 +218,7 @@ type SearchRequestBody struct {
version uint32
filters []*SearchFilter
filters []SearchFilter
}
type SearchRequest struct {
@ -276,7 +276,7 @@ type GetRangeResponse struct {
type GetRangeHashRequestBody struct {
addr *refs.Address
rngs []*Range
rngs []Range
salt []byte
@ -1288,7 +1288,7 @@ func (r *SearchRequestBody) SetVersion(v uint32) {
}
}
func (r *SearchRequestBody) GetFilters() []*SearchFilter {
func (r *SearchRequestBody) GetFilters() []SearchFilter {
if r != nil {
return r.filters
}
@ -1296,7 +1296,7 @@ func (r *SearchRequestBody) GetFilters() []*SearchFilter {
return nil
}
func (r *SearchRequestBody) SetFilters(v []*SearchFilter) {
func (r *SearchRequestBody) SetFilters(v []SearchFilter) {
if r != nil {
r.filters = v
}
@ -1486,7 +1486,7 @@ func (r *GetRangeHashRequestBody) SetAddress(v *refs.Address) {
}
}
func (r *GetRangeHashRequestBody) GetRanges() []*Range {
func (r *GetRangeHashRequestBody) GetRanges() []Range {
if r != nil {
return r.rngs
}
@ -1494,7 +1494,7 @@ func (r *GetRangeHashRequestBody) GetRanges() []*Range {
return nil
}
func (r *GetRangeHashRequestBody) SetRanges(v []*Range) {
func (r *GetRangeHashRequestBody) SetRanges(v []Range) {
if r != nil {
r.rngs = v
}