From e974c8f33eedeb02afc37978ce55978ab347f122 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sun, 13 Apr 2014 14:21:38 +0200 Subject: [PATCH] Preallocate slices in fileset --- files/set.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/files/set.go b/files/set.go index f691f1f07..14491b07a 100644 --- a/files/set.go +++ b/files/set.go @@ -143,7 +143,7 @@ func (m *Set) Need(id uint) []scanner.File { if debug { dlog.Printf("Need(%d)", id) } - var fs []scanner.File + var fs = make([]scanner.File, 0, len(m.globalKey)/2) // Just a guess, but avoids too many reallocations m.Lock() rkID := m.remoteKey[id] for name, gk := range m.globalKey { @@ -162,7 +162,7 @@ func (m *Set) Have(id uint) []scanner.File { if debug { dlog.Printf("Have(%d)", id) } - var fs []scanner.File + var fs = make([]scanner.File, 0, len(m.remoteKey[id])) m.Lock() for _, rk := range m.remoteKey[id] { fs = append(fs, m.files[rk].File) @@ -175,7 +175,7 @@ func (m *Set) Global() []scanner.File { if debug { dlog.Printf("Global()") } - var fs []scanner.File + var fs = make([]scanner.File, 0, len(m.globalKey)) m.Lock() for _, rk := range m.globalKey { fs = append(fs, m.files[rk].File)