unnecessary 'int' in s_conf.c
Joan Sarah Touzet
joant at ieee.org
Sun Jan 9 22:04:38 EST 2005
Looks like the code was committed earlier today. Thanks for the tip!
-Joan
Thus spake Rachel Llorenna (rachies at gmail.com):
> Still, wouldn't it be better to optimize the code onself where
> necessary instead of trusting the compiler to do it? Sometimes not
> depending on the compiler to do the right thing can go a long way...
>
>
> On Fri, 7 Jan 2005 20:25:32 -0500, Lubomir Radev <demond at demond.net> wrote:
> > A smart compiler (which gcc supposedly is) would optimize this code in such
> > way that ret will never be allocated and therefore not referenced - even
> > with the default -O2 only
> >
> >
> > > -----Original Message-----
> > > From: hybrid-bounces at lists.ircd-hybrid.org [mailto:hybrid-
> > > bounces at lists.ircd-hybrid.org] On Behalf Of Rachel Llorenna
> > > Sent: Friday, January 07, 2005 7:02 PM
> > > To: Mailing List: ircd-hybrid
> > > Subject: unnecessary 'int' in s_conf.c
> > >
> > > >From ircd-hybrid-current, serial number 20041220_0. The 'int ret' is
> > > unnecessary in s_conf.c:lookup_confhost (lines 2161-2205),
> > >
> > > static void
> > > lookup_confhost(struct ConfItem *conf)
> > > {
> > > struct AccessItem *aconf;
> > > struct addrinfo hints, *res;
> > > int ret;
> > >
> > > aconf = map_to_conf(conf);
> > >
> > > if (EmptyString(aconf->host) ||
> > > EmptyString(aconf->user))
> > > {
> > > ilog(L_ERROR, "Host/server name error: (%s) (%s)",
> > > aconf->host, conf->name);
> > > return;
> > > }
> > >
> > > if (strchr(aconf->host, '*') ||
> > > strchr(aconf->host, '?'))
> > > return;
> > >
> > > /* Do name lookup now on hostnames given and store the
> > > * ip numbers in conf structure.
> > > */
> > > memset(&hints, 0, sizeof(hints));
> > >
> > > hints.ai_family = AF_UNSPEC;
> > > hints.ai_socktype = SOCK_STREAM;
> > >
> > > /* Get us ready for a bind() and don't bother doing dns lookup */
> > > hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
> > >
> > > if ((ret = irc_getaddrinfo(aconf->host, NULL, &hints, &res)))
> > > {
> > > conf_dns_lookup(aconf);
> > > return;
> > > }
> > >
> > > assert(res != NULL);
> > >
> > > memcpy(&aconf->ipnum, res->ai_addr, res->ai_addrlen);
> > > aconf->ipnum.ss_len = res->ai_addrlen;
> > > aconf->ipnum.ss.ss_family = res->ai_family;
> > > irc_freeaddrinfo(res);
> > > }
> > >
> > > Note that 'ret' is not referenced beyond that single if statement.
> > > Since the return value of irc_getaddrinfo is only used by that one
> > > 'if' statement, why not collapse that line to:
> > > if (irc_getaddrinfo(aconf->host, NULL, &hints, &res)) ...
> > >
> > > And remove the declaration of ret? This would only save a small and
> > > insignificant amount of memory, but at least it doesn't come at the
> > > cost of CPU cycles or other limited resources.
> > > --
> > > Regards,
> > >
> > > Rachel Llorenna (frequency)
> >
> >
>
>
> --
> Regards,
>
> Rachel Llorenna (frequency)
--
- Joan Sarah Touzet |So grey is not the color I expected -
- joant at ieee.org |On someone who's so often touched by grace -
- http://www.atypical.net/ |But always she's the spectre of uncertainty -
- Yes, and................ |I first endured, then faded, then embraced... -
More information about the hybrid
mailing list