This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[Patch, fortran] Use getc/putc instead of fgetc/fputc
- From: Janne Blomqvist <blomqvist dot janne at gmail dot com>
- To: gfortran <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 25 Apr 2007 14:25:37 +0300
- Subject: [Patch, fortran] Use getc/putc instead of fgetc/fputc
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:content-type; b=NiBPpwlewJEgDLDcdoB1+KBOrhq3lbh1zO8nCHQTDyEhc9R9fAViCRx/yH5T+F+FRPGoyaE29hqge4g8JIufyFYulY0dEA2M/bgqYqIv55U1nB3LtJLLG6XIGhCweHMIcb4049bpV7aFgOe3wc3EEmRyMToHDtiG3rV9EYBuUFo=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:content-type; b=GtlD2lZYqpCRZ6MdIsm9mVgVyfV5xAogRPeJ6NLd/E54jP7BhXMSV6DRk5y2s5TX/05hgVxJm3YJxlCwQD0GZJsVkQ42X5ucTj8QCWRoulUTv6L2QxWZmP24baT7C7f9Fq1/msKZaZvWqLC8aBlLSciwTg4iGLznWARCTntkf80=
:ADDPATCH fortran:
Hi,
the attached patch converts the gfortran frontend to use getc/putc
instead of fgetc/fputc.
In normal cases there's no difference, but in pathological cases like
e.g. the example program from PR21130 this patch shaves about 5-10s of
the 90s runtime.
I also tried to use the _unlocked stdio functions, but there was no
difference. It seems the build system is clever enough to substitute the
_unlocked versions automatically when building a single-threaded program.
Regtested on i686-pc-linux-gnu. Ok for trunk?
--
Janne Blomqvist
2007-04-25 Janne Blomqvist <jb@gcc.gnu.org>
* module.c (module_char): Replace fgetc() with
getc().
(write_char): Replace fputc() with putc().
* scanner.c (load_line): Replace fgetc() with getc().
(gfc_read_orig_filename): Likewise.
Index: module.c
===================================================================
--- module.c (revision 124141)
+++ module.c (working copy)
@@ -956,7 +956,7 @@ module_char (void)
{
int c;
- c = fgetc (module_fp);
+ c = getc (module_fp);
if (c == EOF)
bad_module ("Unexpected EOF");
@@ -1276,7 +1276,7 @@ find_enum (const mstring *m)
static void
write_char (char out)
{
- if (fputc (out, module_fp) == EOF)
+ if (putc (out, module_fp) == EOF)
gfc_fatal_error ("Error writing modules file: %s", strerror (errno));
/* Add this to our MD5. */
Index: scanner.c
===================================================================
--- scanner.c (revision 124141)
+++ scanner.c (working copy)
@@ -1033,7 +1033,7 @@ load_line (FILE *input, char **pbuf, int
buffer = *pbuf;
preprocessor_flag = 0;
- c = fgetc (input);
+ c = getc (input);
if (c == '#')
/* In order to not truncate preprocessor lines, we have to
remember that this is one. */
@@ -1042,7 +1042,7 @@ load_line (FILE *input, char **pbuf, int
for (;;)
{
- c = fgetc (input);
+ c = getc (input);
if (c == EOF)
break;
@@ -1121,7 +1121,7 @@ load_line (FILE *input, char **pbuf, int
/* Truncate the rest of the line. */
for (;;)
{
- c = fgetc (input);
+ c = getc (input);
if (c == '\n' || c == EOF)
break;
@@ -1602,7 +1602,7 @@ gfc_read_orig_filename (const char *file
if (gfc_src_file == NULL)
return NULL;
- c = fgetc (gfc_src_file);
+ c = getc (gfc_src_file);
ungetc (c, gfc_src_file);
if (c != '#')
@@ -1618,7 +1618,7 @@ gfc_read_orig_filename (const char *file
if (filename == NULL)
return NULL;
- c = fgetc (gfc_src_file);
+ c = getc (gfc_src_file);
ungetc (c, gfc_src_file);
if (c != '#')