This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] Use getc/putc instead of fgetc/fputc


: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 != '#')

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]