public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [gfortran, committed] Minor cleanups to intrinsic.c
@ 2007-03-30  3:56 Tobias Schlüter
  0 siblings, 0 replies; only message in thread
From: Tobias Schlüter @ 2007-03-30  3:56 UTC (permalink / raw)
  To: Fortran List, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 489 bytes --]


Hi,

trying to understand the intricacies of intrinsic.c, I ran into these 
cleanups which I committed under the obviously correct rule after the 
obligatory testing on i386-darwin.  I'm seeing a recent regression in 
fmt_t_4.f90, but I verified that it is unrelated to this patch.

The patch simplifies conv_name by using the sprintf-like functionality 
built into gfc_get_string, and removes two instances of strcmp, 
replacing them with equivalent pointer comparisons.

Cheers,
- Tobi

[-- Attachment #2: strcmp.diff.txt --]
[-- Type: text/plain, Size: 1606 bytes --]

2007-03-30  Tobias Schlüter  <tobi@gcc.gnu.org>

	* intrinsic.c (conv_name): Let gfc_get_string handle the format.
	(find_conv): Compare pointers instead of calling strcmp.
	(find_sym): Likewise, but ensure that the compared pointer is in
	the global string table.

Index: intrinsic.c
===================================================================
--- intrinsic.c	(revision 123338)
+++ intrinsic.c	(working copy)
@@ -120,12 +120,9 @@ gfc_get_intrinsic_sub_symbol (const char
 static const char *
 conv_name (gfc_typespec *from, gfc_typespec *to)
 {
-  static char name[30];
-
-  sprintf (name, "__convert_%c%d_%c%d", gfc_type_letter (from->type),
-	   from->kind, gfc_type_letter (to->type), to->kind);
-
-  return gfc_get_string (name);
+  return gfc_get_string ("__convert_%c%d_%c%d",
+			 gfc_type_letter (from->type), from->kind,
+			 gfc_type_letter (to->type), to->kind);
 }
 
 
@@ -144,7 +141,7 @@ find_conv (gfc_typespec *from, gfc_types
   sym = conversion;
 
   for (i = 0; i < nconv; i++, sym++)
-    if (strcmp (target, sym->name) == 0)
+    if (target == sym->name)
       return sym;
 
   return NULL;
@@ -701,9 +698,14 @@ add_sym_5s (const char *name, int elemen
 static gfc_intrinsic_sym *
 find_sym (gfc_intrinsic_sym *start, int n, const char *name)
 {
+  /* name may be a user-supplied string, so we must first make sure
+     that we're comparing against a pointer into the global string
+     table.  */
+  const char *p = gfc_get_string (name);
+
   while (n > 0)
     {
-      if (strcmp (name, start->name) == 0)
+      if (p == start->name)
 	return start;
 
       start++;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-03-29 23:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-30  3:56 [gfortran, committed] Minor cleanups to intrinsic.c Tobias Schlüter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).