Commit e974c8f3 authored by Jakob Borg's avatar Jakob Borg

Preallocate slices in fileset

parent 94f5d5b5
...@@ -143,7 +143,7 @@ func (m *Set) Need(id uint) []scanner.File { ...@@ -143,7 +143,7 @@ func (m *Set) Need(id uint) []scanner.File {
if debug { if debug {
dlog.Printf("Need(%d)", id) 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() m.Lock()
rkID := m.remoteKey[id] rkID := m.remoteKey[id]
for name, gk := range m.globalKey { for name, gk := range m.globalKey {
...@@ -162,7 +162,7 @@ func (m *Set) Have(id uint) []scanner.File { ...@@ -162,7 +162,7 @@ func (m *Set) Have(id uint) []scanner.File {
if debug { if debug {
dlog.Printf("Have(%d)", id) dlog.Printf("Have(%d)", id)
} }
var fs []scanner.File var fs = make([]scanner.File, 0, len(m.remoteKey[id]))
m.Lock() m.Lock()
for _, rk := range m.remoteKey[id] { for _, rk := range m.remoteKey[id] {
fs = append(fs, m.files[rk].File) fs = append(fs, m.files[rk].File)
...@@ -175,7 +175,7 @@ func (m *Set) Global() []scanner.File { ...@@ -175,7 +175,7 @@ func (m *Set) Global() []scanner.File {
if debug { if debug {
dlog.Printf("Global()") dlog.Printf("Global()")
} }
var fs []scanner.File var fs = make([]scanner.File, 0, len(m.globalKey))
m.Lock() m.Lock()
for _, rk := range m.globalKey { for _, rk := range m.globalKey {
fs = append(fs, m.files[rk].File) fs = append(fs, m.files[rk].File)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment