[#307] v2/refs/test: Do not allocate memory if !empty
Move all memory allocation and field settings in `Generate...(empty bool)` functions behind `if !empty` check. Do not create empty slices if `empty == true`. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
192382dbfc
commit
704d16c6c6
1 changed files with 9 additions and 5 deletions
|
@ -28,8 +28,10 @@ func GenerateOwnerID(empty bool) *refs.OwnerID {
|
||||||
func GenerateAddress(empty bool) *refs.Address {
|
func GenerateAddress(empty bool) *refs.Address {
|
||||||
m := new(refs.Address)
|
m := new(refs.Address)
|
||||||
|
|
||||||
m.SetObjectID(GenerateObjectID(empty))
|
if !empty {
|
||||||
m.SetContainerID(GenerateContainerID(empty))
|
m.SetObjectID(GenerateObjectID(false))
|
||||||
|
m.SetContainerID(GenerateContainerID(false))
|
||||||
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -45,7 +47,7 @@ func GenerateObjectID(empty bool) *refs.ObjectID {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateObjectIDs(empty bool) []*refs.ObjectID {
|
func GenerateObjectIDs(empty bool) []*refs.ObjectID {
|
||||||
ids := make([]*refs.ObjectID, 0)
|
var ids []*refs.ObjectID
|
||||||
|
|
||||||
if !empty {
|
if !empty {
|
||||||
ids = append(ids,
|
ids = append(ids,
|
||||||
|
@ -67,7 +69,9 @@ func GenerateContainerID(empty bool) *refs.ContainerID {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateContainerIDs(empty bool) (res []*refs.ContainerID) {
|
func GenerateContainerIDs(empty bool) []*refs.ContainerID {
|
||||||
|
var res []*refs.ContainerID
|
||||||
|
|
||||||
if !empty {
|
if !empty {
|
||||||
res = append(res,
|
res = append(res,
|
||||||
GenerateContainerID(false),
|
GenerateContainerID(false),
|
||||||
|
@ -75,7 +79,7 @@ func GenerateContainerIDs(empty bool) (res []*refs.ContainerID) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateSignature(empty bool) *refs.Signature {
|
func GenerateSignature(empty bool) *refs.Signature {
|
||||||
|
|
Loading…
Reference in a new issue