[Dnsmasq-discuss] [PATCH] Optimize inserting records into server list.

Geoff Back geoff at demonlair.co.uk
Sun Sep 19 10:14:33 UTC 2021



On 19/09/2021 10:55, hev via Dnsmasq-discuss wrote:
> Signed-off-by: hev <r at hev.cc>
> ---
>  src/domain-match.c | 11 ++---------
>  1 file changed, 2 insertions(+), 9 deletions(-)
>
> diff --git a/src/domain-match.c b/src/domain-match.c
> index 8f29621..43862f8 100644
> --- a/src/domain-match.c
> +++ b/src/domain-match.c
> @@ -673,18 +673,11 @@ int add_update_server(int flags,
>  	}
>        else
>  	{
> -	  struct server *s;
> -
>  	  memset(serv, 0, sizeof(struct server));
>  	  
>  	  /* Add to the end of the chain, for order */
> -	  if (!daemon->servers)
> -	    daemon->servers = serv;
> -	  else
> -	    {
> -	      for (s = daemon->servers; s->next; s = s->next);
> -	      s->next = serv;
> -	    }
> +	  serv->next = daemon->servers;
> +	  daemon->servers = serv;
>  	  
>  #ifdef HAVE_LOOP
>  	  serv->uid = rand32();

This patch reverses the order of the entries in the linked list so that
the most recently added is at the start instead of the end.
The comment /* Add to the end of the chain, for order */ suggests that
this matters.

Regards,

Geoff.

-- 
Geoff Back
What if we're all just characters in someone's nightmares?




More information about the Dnsmasq-discuss mailing list