diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-06-19 16:45:23 +0000 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-06-19 18:50:13 +0200 |
commit | a4cd5de795926537318f94aa34c9f2579c29fc11 (patch) | |
tree | d97ed6304ab08405ba248e642bb816089f83d1dd | |
parent | 73b1e5746a3f074aa103b5914a02769ff057c56e (diff) | |
download | mdir-a4cd5de795926537318f94aa34c9f2579c29fc11.tar.gz mdir-a4cd5de795926537318f94aa34c9f2579c29fc11.tar.bz2 mdir-a4cd5de795926537318f94aa34c9f2579c29fc11.zip |
ref: Make the slice at once
A small optimization, it will create the slice at once so it won't to
expand multiple time later when append is called.
-rw-r--r-- | worker/worker.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/worker/worker.go b/worker/worker.go index f56716f..06fac36 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -91,10 +91,12 @@ func (w *Worker) StartWorker(model db.EntryModel) { } func (w *Worker) GetJobs() []Job { - jobs := []Job{} + jobs := make([]Job, len(w.jobs)) + count := 0 for k, v := range w.jobs { - jobs = append(jobs, Job{Id: k, Status: v}) + jobs[count] = Job{Id: k, Status: v} + count++ } return jobs |