]> Savannah Git Hosting - gnulib.git/commitdiff
vasnprintf: Optimize last commit.
authorBruno Haible <bruno@clisp.org>
Sun, 13 Apr 2025 18:23:57 +0000 (20:23 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 13 Apr 2025 18:23:57 +0000 (20:23 +0200)
* lib/vasnprintf.c (VASNPRINTF): Optimize a few loops.

ChangeLog
lib/vasnprintf.c

index 3415818382a09df5b9d8614fd1f27da9b2faf6df..c766cc9cca7b24ead8055ad84d9e71055c02b730 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2025-04-13  Bruno Haible  <bruno@clisp.org>
 
+       vasnprintf: Optimize last commit.
+       * lib/vasnprintf.c (VASNPRINTF): Optimize a few loops.
+
        vasnprintf: Consider the grouping rule.
        Reported by Pádraig Brady.
        * lib/vasnprintf.c (grouping_rule, num_thousands_separators): New
index d7e96ac5a6e0782d14ad3d21ae4a490891fffe55..949e14fb175586500f7a48d6610d8fc6a9d66d78 100644 (file)
@@ -5247,9 +5247,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                             int h = *g;
                                             if (h <= 0)
                                               abort ();
-                                            int i;
-                                            for (i = h; i > 0; i--)
+                                            int i = h;
+                                            do
                                               *--p = *digitp++;
+                                            while (--i > 0);
 #   if WIDE_CHAR_VERSION
                                             *--p = thousep[0];
 #   else
@@ -5572,9 +5573,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                                     int h = *g;
                                                     if (h <= 0)
                                                       abort ();
-                                                    int i;
-                                                    for (i = h; i > 0; i--)
+                                                    int i = h;
+                                                    do
                                                       *--p = *digitp++;
+                                                    while (--i > 0);
 #   if WIDE_CHAR_VERSION
                                                     *--p = thousep[0];
 #   else
@@ -5846,9 +5848,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                             int h = *g;
                                             if (h <= 0)
                                               abort ();
-                                            int i;
-                                            for (i = h; i > 0; i--)
+                                            int i = h;
+                                            do
                                               *--p = *digitp++;
+                                            while (--i > 0);
 #   if WIDE_CHAR_VERSION
                                             *--p = thousep[0];
 #   else
@@ -6179,9 +6182,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                                     int h = *g;
                                                     if (h <= 0)
                                                       abort ();
-                                                    int i;
-                                                    for (i = h; i > 0; i--)
+                                                    int i = h;
+                                                    do
                                                       *--p = *digitp++;
+                                                    while (--i > 0);
 #   if WIDE_CHAR_VERSION
                                                     *--p = thousep[0];
 #   else
@@ -7555,14 +7559,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                         int h = *g;
                                         if (h <= 0)
                                           abort ();
-                                        int i;
-                                        for (i = h; i > 0; i--)
+                                        int i = h;
+                                        do
                                           *--q = *--p;
+                                        while (--i > 0);
 # if WIDE_CHAR_VERSION && DCHAR_IS_TCHAR
-                                          *--q = *thousep;
+                                        *--q = *thousep;
 # else
-                                          q -= thousep_len;
-                                          memcpy (q, thousep, thousep_len);
+                                        q -= thousep_len;
+                                        memcpy (q, thousep, thousep_len);
 # endif
                                         insert--;
                                         if (insert == 0)