fix slice memory allocation optimization

This commit is contained in:
bonedaddy 2020-12-22 17:20:58 -08:00
commit 08cad808ef
No known key found for this signature in database
GPG key ID: 5386234333106B29
2 changed files with 5 additions and 5 deletions

View file

@ -72,7 +72,7 @@ func (w *WiFi) MarshalJSON() ([]byte, error) {
doc := wifiJSON{
// we know the length so preallocate to reduce memory allocations
AccessPoints: make([]*AccessPoint, len(w.aps)),
AccessPoints: make([]*AccessPoint, 0, len(w.aps)),
}
for _, ap := range w.aps {
@ -95,7 +95,7 @@ func (w *WiFi) Stations() (list []*Station) {
w.RLock()
defer w.RUnlock()
list = make([]*Station, len(w.aps))
list = make([]*Station, 0, len(w.aps))
for _, ap := range w.aps {
list = append(list, ap.Station)
@ -107,7 +107,7 @@ func (w *WiFi) List() (list []*AccessPoint) {
w.RLock()
defer w.RUnlock()
list = make([]*AccessPoint, len(w.aps))
list = make([]*AccessPoint, 0, len(w.aps))
for _, ap := range w.aps {
list = append(list, ap)