mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #97964 from sxllwx/avoid/alloc_array
modify the elements in the array directly without allocating a new array
This commit is contained in:
commit
c1336094a3
@ -373,13 +373,8 @@ func dedupDeltas(deltas Deltas) Deltas {
|
|||||||
a := &deltas[n-1]
|
a := &deltas[n-1]
|
||||||
b := &deltas[n-2]
|
b := &deltas[n-2]
|
||||||
if out := isDup(a, b); out != nil {
|
if out := isDup(a, b); out != nil {
|
||||||
// `a` and `b` are duplicates. Only keep the one returned from isDup().
|
deltas[n-2] = *out
|
||||||
// TODO: This extra array allocation and copy seems unnecessary if
|
return deltas[:n-1]
|
||||||
// all we do to dedup is compare the new delta with the last element
|
|
||||||
// in `items`, which could be done by mutating `items` directly.
|
|
||||||
// Might be worth profiling and investigating if it is safe to optimize.
|
|
||||||
d := append(Deltas{}, deltas[:n-2]...)
|
|
||||||
return append(d, *out)
|
|
||||||
}
|
}
|
||||||
return deltas
|
return deltas
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user