[#376] reputation: Remove pointers from slices

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-03-02 11:40:47 +03:00 committed by Alex Vanin
parent 30c530e83d
commit 0cab407378
4 changed files with 13 additions and 19 deletions

View file

@ -138,7 +138,7 @@ func (x *PeerToPeerTrust) FromGRPCMessage(m grpc.Message) error {
// TrustsToGRPC converts slice of Trust structures
// to slice of gRPC-generated Trust messages.
func TrustsToGRPC(xs []*Trust) (res []*reputation.Trust) {
func TrustsToGRPC(xs []Trust) (res []*reputation.Trust) {
if xs != nil {
res = make([]*reputation.Trust, 0, len(xs))
@ -152,23 +152,17 @@ func TrustsToGRPC(xs []*Trust) (res []*reputation.Trust) {
// TrustsFromGRPC tries to restore slice of Trust structures from
// slice of gRPC-generated reputation.Trust messages.
func TrustsFromGRPC(xs []*reputation.Trust) (res []*Trust, err error) {
func TrustsFromGRPC(xs []*reputation.Trust) (res []Trust, err error) {
if xs != nil {
res = make([]*Trust, 0, len(xs))
res = make([]Trust, len(xs))
for i := range xs {
var x *Trust
if xs[i] != nil {
x = new(Trust)
err = x.FromGRPCMessage(xs[i])
err = res[i].FromGRPCMessage(xs[i])
if err != nil {
return
}
}
res = append(res, x)
}
}

View file

@ -238,7 +238,7 @@ func (x *AnnounceLocalTrustRequestBody) StableMarshal(buf []byte) ([]byte, error
offset += n
for i := range x.trusts {
n, err = protoutil.NestedStructureMarshal(announceLocalTrustBodyTrustsFNum, buf[offset:], x.trusts[i])
n, err = protoutil.NestedStructureMarshal(announceLocalTrustBodyTrustsFNum, buf[offset:], &x.trusts[i])
if err != nil {
return nil, err
}
@ -253,7 +253,7 @@ func (x *AnnounceLocalTrustRequestBody) StableSize() (size int) {
size += protoutil.UInt64Size(announceLocalTrustBodyEpochFNum, x.epoch)
for i := range x.trusts {
size += protoutil.NestedStructureSize(announceLocalTrustBodyTrustsFNum, x.trusts[i])
size += protoutil.NestedStructureSize(announceLocalTrustBodyTrustsFNum, &x.trusts[i])
}
return

View file

@ -61,13 +61,13 @@ func GenerateGlobalTrust(empty bool) *reputation.GlobalTrust {
return m
}
func GenerateTrusts(empty bool) []*reputation.Trust {
var res []*reputation.Trust
func GenerateTrusts(empty bool) []reputation.Trust {
var res []reputation.Trust
if !empty {
res = append(res,
GenerateTrust(false),
GenerateTrust(false),
*GenerateTrust(false),
*GenerateTrust(false),
)
}

View file

@ -209,7 +209,7 @@ func (x *GlobalTrust) SetSignature(v *refs.Signature) {
type AnnounceLocalTrustRequestBody struct {
epoch uint64
trusts []*Trust
trusts []Trust
}
// GetEpoch returns epoch in which the trust was assessed.
@ -229,7 +229,7 @@ func (x *AnnounceLocalTrustRequestBody) SetEpoch(v uint64) {
}
// GetTrusts returns list of normalized trust values.
func (x *AnnounceLocalTrustRequestBody) GetTrusts() []*Trust {
func (x *AnnounceLocalTrustRequestBody) GetTrusts() []Trust {
if x != nil {
return x.trusts
}
@ -238,7 +238,7 @@ func (x *AnnounceLocalTrustRequestBody) GetTrusts() []*Trust {
}
// SetTrusts sets list of normalized trust values.
func (x *AnnounceLocalTrustRequestBody) SetTrusts(v []*Trust) {
func (x *AnnounceLocalTrustRequestBody) SetTrusts(v []Trust) {
if x != nil {
x.trusts = v
}