[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] maint: use pragma consistently across replacement header

From: Bruno Haible
Subject: Re: [PATCH 2/2] maint: use pragma consistently across replacement headers
Date: Fri, 26 Mar 2010 01:46:49 +0100
User-agent: KMail/1.9.9

Hi Eric,

Eric Blake wrote:
> diff --git a/lib/ctype.in.h b/lib/ctype.in.h
> index ccf222d..fdf9e1e 100644
> --- a/lib/ctype.in.h
> +++ b/lib/ctype.in.h
> @@ -23,12 +23,12 @@
>   * <http://www.opengroup.org/onlinepubs/9699919799/basedefs/ctype.h.html>
>   */
> -#ifndef _GL_CTYPE_H
> -
>  #if __GNUC__ >= 3
>  #endif
> +#ifndef _GL_CTYPE_H
> +
>  /* Include the original <ctype.h>.  */
>  /* The include_next requires a split double-inclusion guard.  */
>  address@hidden@ @NEXT_CTYPE_H@

Did you know that GCC has a special optimization for include files? It
recognizes the idiom that the file starts with a
  #ifndef FOO
directive and ends with the corresponding
directive. When the file is then #included a second time and FOO is
defined, GCC skips the file entirely: it is not parsed again.

You find this implemented in gcc-4.4.3/libcpp/files.c (field 'cmacro')
and gcc-4.4.3/libcpp/directives.c (field 'mi_cmacro'). This optimization
exists in GCC for a long time.

I find it sad that patch destroys this optimization without a very good

The optimization brings some speed. I measured the saving to be 0.0012
seconds of compilation time for a 40 KB include file.

How to reproduce: I took a copy of /usr/include/unistd.h and added the
  #if __GNUC__ >= 3
  #pragma system_header
once inside, and once outside the outermost #ifndef. Then created a
.c file that #includes this file 100 times. Average time of
"gcc -c foo.c" (over 10 runs, real time) was:
  - inside:   0.067 sec
  - outside:  0.190 sec
So, on average, on a 40 KB include file, it saves 0.0012 seconds of
compilation time.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]