From 05a305660554f9e634585464040bc16144b43249 Mon Sep 17 00:00:00 2001 From: lani_karrot Date: Thu, 19 Feb 2026 12:51:11 +0900 Subject: [PATCH] perf: allocation less tdigest --- tdigest/double.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tdigest/double.go b/tdigest/double.go index a63f3af..7201cc5 100644 --- a/tdigest/double.go +++ b/tdigest/double.go @@ -155,18 +155,14 @@ func newDoubleFromInternalStates( // Ensure centroids has enough capacity if cap(centroids) < capacity { - newCentroids := make([]doublePrecisionCentroid, len(centroids), capacity) - copy(newCentroids, centroids) - centroids = newCentroids + centroids = slices.Grow(centroids, capacity) } // Ensure the buffer has enough capacity if buffer == nil { buffer = make([]float64, 0, capacity*bufferMultiplier) } else if cap(buffer) < capacity*bufferMultiplier { - newBuffer := make([]float64, len(buffer), capacity*bufferMultiplier) - copy(newBuffer, buffer) - buffer = newBuffer + buffer = slices.Grow(buffer, capacity*bufferMultiplier) } return &Double{