From d25b90cb6aa7327fd81eaaad4cb892ed021463b4 Mon Sep 17 00:00:00 2001 From: Aditya Harindar Date: Mon, 28 Oct 2019 15:45:30 +0530 Subject: [PATCH] create slice with capacity, when capacity is known This reduces the number of allocations made to the underlying array, while append() attempts to 'grow' the slice beyond its initial capacity --- play.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/play.go b/play.go index e160220d..16410a68 100644 --- a/play.go +++ b/play.go @@ -79,10 +79,8 @@ func (r *Recorder) Events() ([]Event, error) { events := sortedMerge(evOut, evErr) - var ( - out []Event - now = epoch - ) + now := epoch + out := make([]Event, 0, len(events)) for _, e := range events { delay := e.time.Sub(now)