On 04/01/2014 11:36 AM, Ondrej Oprala wrote:
Bruno Haible argued that the cost of a redundant if conditional is
cheaper than the cost of a function call in profiling runs, at least in
the portions of gnulib where he used that idiom. Personally, I like
getting rid of the redundant if (I think the extra CPU cycles spent are
in the noise, until given a profile dump that proves otherwise).
Hmm, is that still up-to-date information?
Doing
$ git grep -B2 '\bfree\(.*;'
on glibc's and gnulib's upstream repo shows no occurences of code such
as "if (foobar) free(foobar);".
Gnulib comes with a script, build-aux/useless-if-before-free, for
identifying such instances. Despite your claim of not finding any
instances in gnulib, this script found several, such as:
./lib/glob.c: if (pglob->gl_pathv[pglob->gl_offs + i] != NULL)
free (pglob->gl_pathv[pglob->gl_offs + i]);
./lib/csharpcomp.c: if (line[0] != NULL)
free (line[0]);
./lib/csharpcomp.c: if (line[1] != NULL)
free (line[1]);
./lib/fstrcmp.c: if (buffer != NULL)
free (buffer);
./lib/vasnprintf.c: if (tmp_roomptr != NULL)
free (tmp_roomptr);