forked from TrueCloudLab/frostfs-sdk-go
[#227] netmap: Pre-calculate resulting slice capacity in flattenNodes
``` name old time/op new time/op delta ManySelects-12 17.5µs ±27% 15.5µs ±24% -11.57% (p=0.024 n=20+20) name old alloc/op new alloc/op delta ManySelects-12 9.03kB ± 0% 8.65kB ± 0% -4.25% (p=0.000 n=20+20) name old allocs/op new allocs/op delta ManySelects-12 86.0 ± 0% 82.0 ± 0% -4.65% (p=0.000 n=20+20) ``` Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
a8fd2ef954
commit
9c47fca7c2
1 changed files with 8 additions and 1 deletions
|
@ -21,7 +21,14 @@ func NewNetmap(nodes Nodes) (*Netmap, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func flattenNodes(ns []Nodes) Nodes {
|
func flattenNodes(ns []Nodes) Nodes {
|
||||||
result := make(Nodes, 0, len(ns))
|
var sz, i int
|
||||||
|
|
||||||
|
for i = range ns {
|
||||||
|
sz += len(ns[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make(Nodes, 0, sz)
|
||||||
|
|
||||||
for i := range ns {
|
for i := range ns {
|
||||||
result = append(result, ns[i]...)
|
result = append(result, ns[i]...)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue