From ed2506a4dc8dc06fb63a5ce6edee77191d27fdf2 Mon Sep 17 00:00:00 2001
From: Bryce McKinlay <bryce@mckinlay.net.nz>
Date: Tue, 21 Oct 2003 23:59:46 +0000
Subject: [PATCH] re PR java/12586 (gnu.java.net name mangling bug)

        Fix for PR java/12586.
        * mangle.c (find_compression_record_match): Don't iterate through
        package namespace elements unless they all match compression_table
        entries.

From-SVN: r72779
---
 gcc/java/ChangeLog |  7 +++++++
 gcc/java/mangle.c  | 49 +++++++++++++++++++---------------------------
 2 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog
index 326e8e8db34e..35dce1c3b8b6 100644
--- a/gcc/java/ChangeLog
+++ b/gcc/java/ChangeLog
@@ -1,3 +1,10 @@
+2003-10-22  Bryce McKinlay  <bryce@mckinlay.net.nz>
+
+	Fix for	PR java/12586.
+	* mangle.c (find_compression_record_match): Don't iterate through
+	package namespace elements unless they all match compression_table
+	entries.
+
 2003-10-20  Kelley Cook  <kcook@gcc.gnu.org>
 
 	* Make-lang.in (info): Honor $(parsedir) and $(docobjdir).
diff --git a/gcc/java/mangle.c b/gcc/java/mangle.c
index e545cbc1fac1..0c8435cb71c9 100644
--- a/gcc/java/mangle.c
+++ b/gcc/java/mangle.c
@@ -287,38 +287,29 @@ find_compression_array_template_match (tree string)
 static int
 find_compression_record_match (tree type, tree *next_current)
 {
-  int i, match;
+  int i, match = -1;
   tree current, saved_current = NULL_TREE;
 
-  /* Search from the beginning for something that matches TYPE, even
-     partially. */
-  for (current = TYPE_PACKAGE_LIST (type), i = 0, match = -1; current;
-       current = TREE_CHAIN (current))
+  current = TYPE_PACKAGE_LIST (type);
+      
+  for (i = 0; i < compression_next; i++)
     {
-      int j;
-      for (j = i; j < compression_next; j++)
-	if (TREE_VEC_ELT (compression_table, j) == TREE_PURPOSE (current))
-	  {
-	    match = i = j;
-	    saved_current = current;
-	    i++;
-	    break;
-	  }
-        else if (atms && TREE_VEC_ELT (compression_table, j) == atms)
-          {
-            /* Skip over a "6JArray". */
-          }
-	else
-	  {
-	    /* We don't want to match an element that appears in the middle
-	    of a package name, so skip forward to the next complete type name.
-	    IDENTIFIER_NODEs (except for a "6JArray") are partial package
-            names while RECORD_TYPEs represent complete type names. */
-	    while (j < compression_next 
-		   && TREE_CODE (TREE_VEC_ELT (compression_table, j)) == 
-		      IDENTIFIER_NODE)
-	      j++;
-	  }
+      tree compression_entry = TREE_VEC_ELT (compression_table, i);
+      if (current && compression_entry == TREE_PURPOSE (current))
+        {
+	  match = i;
+	  saved_current = current;
+	  current = TREE_CHAIN (current);
+	}
+      else
+	/* We don't want to match an element that appears in the middle
+	   of a package name, so skip forward to the next complete type name.
+	   IDENTIFIER_NODEs (except for a "6JArray") are partial package
+	   names while RECORD_TYPEs represent complete type names. */
+	while (i < compression_next 
+	       && TREE_CODE (compression_entry) == IDENTIFIER_NODE
+	       && compression_entry != atms)
+	  compression_entry = TREE_VEC_ELT (compression_table, ++i);
     }
 
   if (!next_current)
-- 
GitLab