server+lnwire: pre-allocate address slices

This commit is contained in:
Olaoluwa Osuntokun 2017-03-29 16:55:28 -07:00
parent cabaf1816b
commit afe77853b7
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 7 additions and 5 deletions

@ -619,13 +619,15 @@ func readElement(r io.Reader, element interface{}) error {
}
case *[]net.Addr:
var addresses []net.Addr
var numAddrs [2]byte
if _, err = io.ReadFull(r, numAddrs[:]); err != nil {
var numAddrsBytes [2]byte
if _, err = io.ReadFull(r, numAddrsBytes[:]); err != nil {
return err
}
for i := 0; i < int(binary.BigEndian.Uint16(numAddrs[:])); i++ {
numAddrs := binary.BigEndian.Uint16(numAddrsBytes[:])
addresses := make([]net.Addr, 0, numAddrs)
for i := 0; i < int(numAddrs); i++ {
var descriptor [1]byte
if _, err = io.ReadFull(r, descriptor[:]); err != nil {
return err

@ -156,7 +156,7 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
// If external IP addresses have been specified, add those to the list
// of this server's addresses.
selfAddrs := make([]net.Addr, 0)
selfAddrs := make([]net.Addr, 0, len(cfg.ExternalIPs))
for _, ip := range cfg.ExternalIPs {
addr, err := net.ResolveTCPAddr("tcp", ip)
if err != nil {