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

hev r at hev.cc
Mon Sep 20 01:47:48 UTC 2021


On Sun, Sep 19, 2021 at 7:26 PM Geoff Back <geoff at demonlair.co.uk> wrote:
>
>
>
> 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.

Yeah. I sent the patch v2 to keep the original order.

Test configs: https://github.com/felixonmars/dnsmasq-china-list/

Regards,
hev



More information about the Dnsmasq-discuss mailing list