From c7901fa3e466dc459badb28f9157726eeefd7a5a Mon Sep 17 00:00:00 2001 From: scott Date: Tue, 12 Jan 2021 19:58:21 +0800 Subject: [PATCH] modify the elements in the array directly without allocating a new array Kubernetes-commit: 238fce9357634502badbcc3704b0655cf8c378c3 --- tools/cache/delta_fifo.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tools/cache/delta_fifo.go b/tools/cache/delta_fifo.go index ea25122a..1464d34c 100644 --- a/tools/cache/delta_fifo.go +++ b/tools/cache/delta_fifo.go @@ -373,13 +373,8 @@ func dedupDeltas(deltas Deltas) Deltas { a := &deltas[n-1] b := &deltas[n-2] if out := isDup(a, b); out != nil { - // `a` and `b` are duplicates. Only keep the one returned from isDup(). - // TODO: This extra array allocation and copy seems unnecessary if - // 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) + deltas[n-2] = *out + return deltas[:n-1] } return deltas }