]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: don't use frag_more to repeat copies
authorAlan Modra <amodra@gmail.com>
Thu, 19 Feb 2026 04:48:12 +0000 (15:18 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 19 Feb 2026 06:19:52 +0000 (16:49 +1030)
It's more elegant to use the repeat capability of an rs_fill frag_var,
and dramatically reduces memory usage for large repeat counts.

For ideal minimal memory use, repeats of up to the 100 bytes or so of
frag overhead should be handled by frag_more, but I don't care to
optimise those cases.  It's enough that the most common case of a
single output value uses frag_more, while stress testing the assembler
with huge repeats doesn't run into OOM.

* read.c (float_cons): Repeat output using an rs_fill frag_var
rather than looping with frag_more.
(s_float_space): Likewise.

gas/read.c

index 40804d44845ae880bdf611790040385e0efc32dd..29dace68958bc6f4b08c7eaf4bcff335b9ef10de 100644 (file)
@@ -3873,6 +3873,7 @@ s_float_space (int float_type)
   char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
   char *stop = NULL;
   char stopc = 0;
+  char *p;
 
 #ifdef md_cons_align
   md_cons_align (1);
@@ -3906,13 +3907,11 @@ s_float_space (int float_type)
       return;
     }
 
-  while (--count >= 0)
-    {
-      char *p;
-
-      p = frag_more (flen);
-      memcpy (p, temp, flen);
-    }
+  if (count == 1)
+    p = frag_more (flen);
+  else
+    p = frag_var (rs_fill, flen, flen, 0, NULL, count, NULL);
+  memcpy (p, temp, flen);
 
   demand_empty_rest_of_line ();
 
@@ -5173,12 +5172,11 @@ float_cons (/* Clobbers input_line-pointer, checks end-of-line.  */
                count = count_exp.X_add_number;
            }
 #endif
-
-         while (--count >= 0)
-           {
-             p = frag_more (length);
-             memcpy (p, temp, length);
-           }
+         if (count == 1)
+           p = frag_more (length);
+         else
+           p = frag_var (rs_fill, length, length, 0, NULL, count, NULL);
+         memcpy (p, temp, length);
        }
       SKIP_WHITESPACE ();
     }