]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
unistr: Replace some 'continue;' statements with if/else.
authorBruno Haible <bruno@clisp.org>
Sun, 23 Nov 2025 21:34:06 +0000 (22:34 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 23 Nov 2025 21:34:35 +0000 (22:34 +0100)
* lib/unistr/u16-cmp.c (u16_cmp): Use if/else instead of 'continue;'.
* lib/unistr/u16-strcmp.c (u16_strcmp): Likewise.
* lib/unistr/u16-strncmp.c (u16_strncmp): Likewise.
* lib/unistr/u32-cmp.c (u32_cmp): Likewise.
* lib/unistr/u32-strcmp.c (u32_strcmp): Likewise.
* lib/unistr/u32-strncmp.c (u32_strncmp): Likewise.

ChangeLog
lib/unistr/u16-cmp.c
lib/unistr/u16-strcmp.c
lib/unistr/u16-strncmp.c
lib/unistr/u32-cmp.c
lib/unistr/u32-strcmp.c
lib/unistr/u32-strncmp.c

index a5de9bc51a69efb5cccb744abf518dfa4b1a9f6e..b8d3e21e799f902a2f06f7d1469afcedd134337a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2025-11-23  Bruno Haible  <bruno@clisp.org>
+
+       unistr: Replace some 'continue;' statements with if/else.
+       * lib/unistr/u16-cmp.c (u16_cmp): Use if/else instead of 'continue;'.
+       * lib/unistr/u16-strcmp.c (u16_strcmp): Likewise.
+       * lib/unistr/u16-strncmp.c (u16_strncmp): Likewise.
+       * lib/unistr/u32-cmp.c (u32_cmp): Likewise.
+       * lib/unistr/u32-strcmp.c (u32_strcmp): Likewise.
+       * lib/unistr/u32-strncmp.c (u32_strncmp): Likewise.
+
 2025-11-23  Paul Eggert  <eggert@cs.ucla.edu>
 
        count-leading-zeros: fix 2025-11-18 regression
index cedf9d2ee61403732bbd439fe9ddb819f80eb1de..8bba1bd2a490849522cb5a8d0c7e85bc066264a7 100644 (file)
@@ -34,29 +34,27 @@ u16_cmp (const uint16_t *s1, const uint16_t *s2, size_t n)
   /* Note that the UTF-16 encoding does NOT preserve lexicographic order.
      Namely, if uc1 is a 16-bit character and [uc2a,uc2b] is a surrogate pair,
      we must enforce uc1 < [uc2a,uc2b], even if uc1 > uc2a.  */
-  for (; n > 0;)
+  for (; n > 0; n--)
     {
       uint16_t c1 = *s1++;
       uint16_t c2 = *s2++;
-      if (c1 == c2)
+      if (c1 != c2)
         {
-          n--;
-          continue;
+          if (c1 < 0xd800 || c1 >= 0xe000)
+            {
+              if (!(c2 < 0xd800 || c2 >= 0xe000))
+                /* c2 is a surrogate, but c1 is not.  */
+                return -1;
+            }
+          else
+            {
+              if (c2 < 0xd800 || c2 >= 0xe000)
+                /* c1 is a surrogate, but c2 is not.  */
+                return 1;
+            }
+          return (int)c1 - (int)c2;
+          /* > 0 if c1 > c2, < 0 if c1 < c2. */
         }
-      if (c1 < 0xd800 || c1 >= 0xe000)
-        {
-          if (!(c2 < 0xd800 || c2 >= 0xe000))
-            /* c2 is a surrogate, but c1 is not.  */
-            return -1;
-        }
-      else
-        {
-          if (c2 < 0xd800 || c2 >= 0xe000)
-            /* c1 is a surrogate, but c2 is not.  */
-            return 1;
-        }
-      return (int)c1 - (int)c2;
-      /* > 0 if c1 > c2, < 0 if c1 < c2. */
     }
   return 0;
 }
index 8dd332d771ce1ed2f089762c903f619ad7dc6da0..5effbbdc92947a773f71d8fae87e75c44a58eedb 100644 (file)
@@ -38,21 +38,22 @@ u16_strcmp (const uint16_t *s1, const uint16_t *s2)
     {
       uint16_t c1 = *s1++;
       uint16_t c2 = *s2++;
-      if (c1 != 0 && c1 == c2)
-        continue;
-      if (c1 < 0xd800 || c1 >= 0xe000)
+      if (c1 == 0 || c1 != c2)
         {
-          if (!(c2 < 0xd800 || c2 >= 0xe000))
-            /* c2 is a surrogate, but c1 is not.  */
-            return -1;
+          if (c1 < 0xd800 || c1 >= 0xe000)
+            {
+              if (!(c2 < 0xd800 || c2 >= 0xe000))
+                /* c2 is a surrogate, but c1 is not.  */
+                return -1;
+            }
+          else
+            {
+              if (c2 < 0xd800 || c2 >= 0xe000)
+                /* c1 is a surrogate, but c2 is not.  */
+                return 1;
+            }
+          return (int)c1 - (int)c2;
+          /* > 0 if c1 > c2, < 0 if c1 < c2. */
         }
-      else
-        {
-          if (c2 < 0xd800 || c2 >= 0xe000)
-            /* c1 is a surrogate, but c2 is not.  */
-            return 1;
-        }
-      return (int)c1 - (int)c2;
-      /* > 0 if c1 > c2, < 0 if c1 < c2. */
     }
 }
index 3bba6e229b92da05c7c4e65f1538f9c80c8241fb..598815dbd1d5067897ecc599ff7e0e63165fc332 100644 (file)
@@ -34,29 +34,27 @@ u16_strncmp (const uint16_t *s1, const uint16_t *s2, size_t n)
   /* Note that the UTF-16 encoding does NOT preserve lexicographic order.
      Namely, if uc1 is a 16-bit character and [uc2a,uc2b] is a surrogate pair,
      we must enforce uc1 < [uc2a,uc2b], even if uc1 > uc2a.  */
-  for (; n > 0;)
+  for (; n > 0; n--)
     {
       uint16_t c1 = *s1++;
       uint16_t c2 = *s2++;
-      if (c1 != 0 && c1 == c2)
+      if (c1 == 0 || c1 != c2)
         {
-          n--;
-          continue;
+          if (c1 < 0xd800 || c1 >= 0xe000)
+            {
+              if (!(c2 < 0xd800 || c2 >= 0xe000))
+                /* c2 is a surrogate, but c1 is not.  */
+                return -1;
+            }
+          else
+            {
+              if (c2 < 0xd800 || c2 >= 0xe000)
+                /* c1 is a surrogate, but c2 is not.  */
+                return 1;
+            }
+          return (int)c1 - (int)c2;
+          /* > 0 if c1 > c2, < 0 if c1 < c2, = 0 if c1 and c2 are both 0. */
         }
-      if (c1 < 0xd800 || c1 >= 0xe000)
-        {
-          if (!(c2 < 0xd800 || c2 >= 0xe000))
-            /* c2 is a surrogate, but c1 is not.  */
-            return -1;
-        }
-      else
-        {
-          if (c2 < 0xd800 || c2 >= 0xe000)
-            /* c1 is a surrogate, but c2 is not.  */
-            return 1;
-        }
-      return (int)c1 - (int)c2;
-      /* > 0 if c1 > c2, < 0 if c1 < c2, = 0 if c1 and c2 are both 0. */
     }
   return 0;
 }
index e38c7e8137c7832e50cb83b12de686b4623082e1..1b3ae43969af5bcfea01c52631b99307d3de467a 100644 (file)
 int
 u32_cmp (const uint32_t *s1, const uint32_t *s2, size_t n)
 {
-  for (; n > 0;)
+  for (; n > 0; n--)
     {
       uint32_t uc1 = *s1++;
       uint32_t uc2 = *s2++;
-      if (uc1 == uc2)
+      if (uc1 != uc2)
         {
-          n--;
-          continue;
+          /* Note that uc1 and uc2 each have at most 31 bits. */
+          return (int)uc1 - (int)uc2;
+          /* > 0 if uc1 > uc2, < 0 if uc1 < uc2. */
         }
-      /* Note that uc1 and uc2 each have at most 31 bits. */
-      return (int)uc1 - (int)uc2;
-      /* > 0 if uc1 > uc2, < 0 if uc1 < uc2. */
     }
   return 0;
 }
index d0ec7d3c87119bb9adab16a2e09d450c81a2cf03..45af280cc69f7bec0b554e40a997abfc7e9cecb0 100644 (file)
@@ -35,10 +35,11 @@ u32_strcmp (const uint32_t *s1, const uint32_t *s2)
     {
       uint32_t uc1 = *s1++;
       uint32_t uc2 = *s2++;
-      if (uc1 != 0 && uc1 == uc2)
-        continue;
-      /* Note that uc1 and uc2 each have at most 31 bits. */
-      return (int)uc1 - (int)uc2;
-      /* > 0 if uc1 > uc2, < 0 if uc1 < uc2. */
+      if (uc1 == 0 || uc1 != uc2)
+        {
+          /* Note that uc1 and uc2 each have at most 31 bits. */
+          return (int)uc1 - (int)uc2;
+          /* > 0 if uc1 > uc2, < 0 if uc1 < uc2. */
+        }
     }
 }
index 98461ad76c2fb86c09900a86a195dfbf19637468..c2a7c6dbd7fecb9288b5d3ebc8ebad84e572df02 100644 (file)
 int
 u32_strncmp (const uint32_t *s1, const uint32_t *s2, size_t n)
 {
-  for (; n > 0;)
+  for (; n > 0; n--)
     {
       uint32_t uc1 = *s1++;
       uint32_t uc2 = *s2++;
-      if (uc1 != 0 && uc1 == uc2)
+      if (uc1 == 0 || uc1 != uc2)
         {
-          n--;
-          continue;
+          /* Note that uc1 and uc2 each have at most 31 bits. */
+          return (int)uc1 - (int)uc2;
+          /* > 0 if uc1 > uc2, < 0 if uc1 < uc2, = 0 if uc1 and uc2 are both 0.  */
         }
-      /* Note that uc1 and uc2 each have at most 31 bits. */
-      return (int)uc1 - (int)uc2;
-      /* > 0 if uc1 > uc2, < 0 if uc1 < uc2, = 0 if uc1 and uc2 are both 0.  */
     }
   return 0;
 }