]> Savannah Git Hosting - gnulib.git/commitdiff
vasnwprintf: Optimize handling of %c directive.
authorBruno Haible <bruno@clisp.org>
Wed, 19 Jun 2024 13:20:21 +0000 (15:20 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 19 Jun 2024 13:20:21 +0000 (15:20 +0200)
* lib/vasnprintf.c (VASNPRINTF): Use a single ENSURE_ALLOCATION instead
of two.

ChangeLog
lib/vasnprintf.c

index 34e01291aedbe247864a04fa08da4885dbc8c549..0f89dacf4aa758fa2261e794d14d34fd09af0df3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-06-19  Bruno Haible  <bruno@clisp.org>
+
+       vasnwprintf: Optimize handling of %c directive.
+       * lib/vasnprintf.c (VASNPRINTF): Use a single ENSURE_ALLOCATION instead
+       of two.
+
 2024-06-19  Bruno Haible  <bruno@clisp.org>
 
        u*-vasnprintf: Fix a rare memory leak.
index ed2052c0aedff057589b851640d7328514ed8f67..1838ded22db8a815a4f7524372f02d8e50b6016e 100644 (file)
@@ -3708,24 +3708,26 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     /* Invalid or incomplete multibyte character.  */
                     goto fail_with_EILSEQ;
 
-                  if (1 < width && !(flags & FLAG_LEFT))
-                    {
-                      size_t n = width - 1;
-                      ENSURE_ALLOCATION (xsum (length, n));
-                      DCHAR_SET (result + length, ' ', n);
-                      length += n;
-                    }
+                  {
+                    size_t total = (1 < width ? width : 1);
+                    ENSURE_ALLOCATION (xsum (length, total));
+
+                    if (1 < width && !(flags & FLAG_LEFT))
+                      {
+                        size_t n = width - 1;
+                        DCHAR_SET (result + length, ' ', n);
+                        length += n;
+                      }
 
-                  ENSURE_ALLOCATION (xsum (length, 1));
-                  result[length++] = wc;
+                    result[length++] = wc;
 
-                  if (1 < width && (flags & FLAG_LEFT))
-                    {
-                      size_t n = width - 1;
-                      ENSURE_ALLOCATION (xsum (length, n));
-                      DCHAR_SET (result + length, ' ', n);
-                      length += n;
-                    }
+                    if (1 < width && (flags & FLAG_LEFT))
+                      {
+                        size_t n = width - 1;
+                        DCHAR_SET (result + length, ' ', n);
+                        length += n;
+                      }
+                  }
                 }
               }
 #endif