[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
> @PRAGMA_SYSTEM_HEADER@
> #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
#endif
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
reason.
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
#endif
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.
Bruno
- [PATCH] arpa/inet: fix mingw compilation warning, Eric Blake, 2010/03/24
- [PATCH 2/2] maint: use pragma consistently across replacement headers, Eric Blake, 2010/03/25
- Re: [PATCH 2/2] maint: use pragma consistently across replacement headers,
Bruno Haible <=
- Re: [PATCH 2/2] maint: use pragma consistently across replacement headers, Eric Blake, 2010/03/26
- Re: [PATCH 2/2] maint: use pragma consistently across replacement headers, Bruno Haible, 2010/03/28
- Re: [PATCH 2/2] maint: use pragma consistently across replacement headers, Eric Blake, 2010/03/29
- Re: [PATCH 2/2] maint: use pragma consistently across replacement headers, Bruno Haible, 2010/03/29
- Re: [PATCH 2/2] maint: use pragma consistently across replacement headers, Jim Meyering, 2010/03/30