mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 13:33:21 -07:00
fix slice memory allocation optimization
This commit is contained in:
parent
ac4b1f6e9e
commit
08cad808ef
2 changed files with 5 additions and 5 deletions
|
@ -72,7 +72,7 @@ func (w *WiFi) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
doc := wifiJSON{
|
doc := wifiJSON{
|
||||||
// we know the length so preallocate to reduce memory allocations
|
// 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 {
|
for _, ap := range w.aps {
|
||||||
|
@ -95,7 +95,7 @@ func (w *WiFi) Stations() (list []*Station) {
|
||||||
w.RLock()
|
w.RLock()
|
||||||
defer w.RUnlock()
|
defer w.RUnlock()
|
||||||
|
|
||||||
list = make([]*Station, len(w.aps))
|
list = make([]*Station, 0, len(w.aps))
|
||||||
|
|
||||||
for _, ap := range w.aps {
|
for _, ap := range w.aps {
|
||||||
list = append(list, ap.Station)
|
list = append(list, ap.Station)
|
||||||
|
@ -107,7 +107,7 @@ func (w *WiFi) List() (list []*AccessPoint) {
|
||||||
w.RLock()
|
w.RLock()
|
||||||
defer w.RUnlock()
|
defer w.RUnlock()
|
||||||
|
|
||||||
list = make([]*AccessPoint, len(w.aps))
|
list = make([]*AccessPoint, 0, len(w.aps))
|
||||||
|
|
||||||
for _, ap := range w.aps {
|
for _, ap := range w.aps {
|
||||||
list = append(list, ap)
|
list = append(list, ap)
|
||||||
|
|
|
@ -37,7 +37,7 @@ func (ap *AccessPoint) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
doc := apJSON{
|
doc := apJSON{
|
||||||
Station: ap.Station,
|
Station: ap.Station,
|
||||||
Clients: make([]*Station, len(ap.clients)),
|
Clients: make([]*Station, 0, len(ap.clients)),
|
||||||
Handshake: ap.withKeyMaterial,
|
Handshake: ap.withKeyMaterial,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ func (ap *AccessPoint) Clients() (list []*Station) {
|
||||||
ap.RLock()
|
ap.RLock()
|
||||||
defer ap.RUnlock()
|
defer ap.RUnlock()
|
||||||
|
|
||||||
list = make([]*Station, len(ap.clients))
|
list = make([]*Station, 0, len(ap.clients))
|
||||||
for _, c := range ap.clients {
|
for _, c := range ap.clients {
|
||||||
list = append(list, c)
|
list = append(list, c)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue