https://gcc.gnu.org/g:210a11e1b2be185e0efacdce7d867c54d4e7d4b4

commit r16-6421-g210a11e1b2be185e0efacdce7d867c54d4e7d4b4
Author: Jose E. Marchesi <[email protected]>
Date:   Sun Dec 28 16:13:22 2025 +0100

    a68: cache moifs in a68_open_packet
    
    Signed-off-by: Jose E. Marchesi <[email protected]>
    
    gcc/algol68/ChangeLog
    
            * a68-imports.cc (a68_open_packet): Use already decoded moifs
            if present.

Diff:
---
 gcc/algol68/a68-imports.cc | 90 +++++++++++++++++++++++++++-------------------
 1 file changed, 53 insertions(+), 37 deletions(-)

diff --git a/gcc/algol68/a68-imports.cc b/gcc/algol68/a68-imports.cc
index a13e05940e0f..b2297a144953 100644
--- a/gcc/algol68/a68-imports.cc
+++ b/gcc/algol68/a68-imports.cc
@@ -1356,49 +1356,65 @@ a68_decode_moifs (const char *data, size_t size, const 
char **errstr)
 MOIF_T *
 a68_open_packet (const char *module)
 {
-  /* Look in the modules location maps to see if there is an entry for MODULE.
-     If there is one, use the specified filename.  Otherwise canonicalize the
-     module name to a file name.  */
-  char *filename;
-  const char **pfilename = A68_MODULE_FILES->get (module);
-  if (pfilename == NULL)
-    {
-      /* Turn the module indicant in MODULE to lower-case.  */
-      filename = (char *) alloca (strlen (module) + 1);
-      size_t i = 0;
-      for (; i < strlen (module); i++)
-       filename[i] = TOLOWER (module[i]);
-      filename[i] = '\0';
-    }
-  else
+  /* We may have a suitable moif already decoded for the requested module.  If
+     so, use it.  */
+
+  MOIF_T *moif = TOP_MOIF (&A68_JOB);
+  while (moif != NO_MOIF)
     {
-      size_t len = strlen (*pfilename) + 1;
-      filename = (char *) alloca (len);
-      memcpy (filename, *pfilename, len);
+      if (strcmp (NAME (moif), module) == 0)
+       break;
+      FORWARD (moif);
     }
 
-  /* Try to read exports data in a buffer.  */
-  char *exports_data;
-  size_t exports_data_size;
-  exports_data = a68_get_packet_exports (std::string (filename),
-                                        std::string ("."),
-                                        &exports_data_size);
-  if (exports_data == NULL)
-    return NULL;
+  /* If we didn't find already decoded exports for the requested module, look
+     in the modules location maps to see if there is an entry for MODULE.  If
+     there is one, use the specified filename.  Otherwise canonicalize the
+     module name to a file name.  */
 
-  /* Got some data.  Decode it into a list of moif.  */
-  const char *errstr = NULL;
-  if (!a68_decode_moifs (exports_data, exports_data_size, &errstr))
+  if (moif == NO_MOIF)
     {
-      a68_error (NO_NODE, "%s", errstr);
-      return NULL;
-    }
+      char *filename;
+      const char **pfilename = A68_MODULE_FILES->get (module);
+      if (pfilename == NULL)
+       {
+         /* Turn the module indicant in MODULE to lower-case.  */
+         filename = (char *) alloca (strlen (module) + 1);
+         size_t i = 0;
+         for (; i < strlen (module); i++)
+           filename[i] = TOLOWER (module[i]);
+         filename[i] = '\0';
+       }
+      else
+       {
+         size_t len = strlen (*pfilename) + 1;
+         filename = (char *) alloca (len);
+         memcpy (filename, *pfilename, len);
+       }
 
-  /* The androids we are looking for are likely to be now in the global
-     list.  */
-  MOIF_T *moif = TOP_MOIF (&A68_JOB);
-  while (moif != NO_MOIF && strcmp (NAME (moif), module) != 0)
-    FORWARD (moif);
+      /* Try to read exports data in a buffer.  */
+      char *exports_data;
+      size_t exports_data_size;
+      exports_data = a68_get_packet_exports (std::string (filename),
+                                            std::string ("."),
+                                            &exports_data_size);
+      if (exports_data == NULL)
+       return NULL;
+
+      /* Got some data.  Decode it into a list of moif.  */
+      const char *errstr = NULL;
+      if (!a68_decode_moifs (exports_data, exports_data_size, &errstr))
+       {
+         a68_error (NO_NODE, "%s", errstr);
+         return NULL;
+       }
+
+      /* The androids we are looking for are likely to be now in the global
+        list.  */
+      moif = TOP_MOIF (&A68_JOB);
+      while (moif != NO_MOIF && strcmp (NAME (moif), module) != 0)
+       FORWARD (moif);
+    }
 
   /* If we got a moif, we need to make sure that it doesn't introduce new modes
      that are equivalent to any mode in the compiler's mode list.  If it does,

Reply via email to