]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[RFA] Improve initialization of objects when the initializer has trailing zeros.
authorJeff Law <jeffreyalaw@gmail.com>
Sat, 9 Jul 2022 15:11:00 +0000 (11:11 -0400)
committerJeff Law <jeffreyalaw@gmail.com>
Sat, 9 Jul 2022 15:11:00 +0000 (11:11 -0400)
gcc/

* expr.cc (store_expr): Identify trailing NULs in a STRING_CST
initializer and use clear_storage rather than copying the
NULs to the destination array.

gcc/expr.cc

index eb280e6cac3b1e7f2f9d001b1405633d1e3321c9..f9753d48245d56039206647be8576246a3b25ed3 100644 (file)
@@ -6088,6 +6088,17 @@ store_expr (tree exp, rtx target, int call_param_p,
        }
 
       str_copy_len = TREE_STRING_LENGTH (str);
+
+      /* Trailing NUL bytes in EXP will be handled by the call to
+        clear_storage, which is more efficient than copying them from
+        the STRING_CST, so trim those from STR_COPY_LEN.  */
+      while (str_copy_len)
+       {
+         if (TREE_STRING_POINTER (str)[str_copy_len - 1])
+           break;
+         str_copy_len--;
+       }
+
       if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0)
        {
          str_copy_len += STORE_MAX_PIECES - 1;