From 28e519b72d831501a57b5455dc33ba054f5e927c Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Tue, 29 Aug 2017 16:54:53 -0500 Subject: [PATCH] tcp_output: move useg assignment to right before segment while loop There were a couple cases in-between that could cause an exit from tcp_output which don't use useg. With large send buffers, pcb->unacked may be large and calculating useg is wasted in these exit cases Some compilers may be re-ordering this already, but it doesn't hurt to correctly arrange the code --- src/core/tcp_out.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 2f1fab74..e5216787 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -1151,12 +1151,6 @@ tcp_output(struct tcp_pcb *pcb) lwip_ntohl(seg->tcphdr->seqno), pcb->lastack)); } - /* useg should point to last segment on unacked queue */ - useg = pcb->unacked; - if (useg != NULL) { - for (; useg->next != NULL; useg = useg->next); - } - netif = tcp_route(pcb, &pcb->local_ip, &pcb->remote_ip); if (netif == NULL) { return ERR_RTE; @@ -1192,6 +1186,12 @@ tcp_output(struct tcp_pcb *pcb) } /* Stop persist timer, above conditions are not active */ pcb->persist_backoff = 0; + + /* useg should point to last segment on unacked queue */ + useg = pcb->unacked; + if (useg != NULL) { + for (; useg->next != NULL; useg = useg->next); + } /* data available and window allows it to be sent? */ while (seg != NULL && lwip_ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len <= wnd) {