> 2025-11-18 Bruno Haible <[email protected]> > > lib: Replace some 'continue;' statements with if/else. >
Some more of the same kind: 2025-11-23 Bruno Haible <[email protected]> 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. [git diff -w] diff --git a/lib/unistr/u16-cmp.c b/lib/unistr/u16-cmp.c index cedf9d2ee6..8bba1bd2a4 100644 --- a/lib/unistr/u16-cmp.c +++ b/lib/unistr/u16-cmp.c @@ -34,15 +34,12 @@ 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)) @@ -58,5 +55,6 @@ u16_cmp (const uint16_t *s1, const uint16_t *s2, size_t n) return (int)c1 - (int)c2; /* > 0 if c1 > c2, < 0 if c1 < c2. */ } + } return 0; } diff --git a/lib/unistr/u16-strcmp.c b/lib/unistr/u16-strcmp.c index 8dd332d771..5effbbdc92 100644 --- a/lib/unistr/u16-strcmp.c +++ b/lib/unistr/u16-strcmp.c @@ -38,8 +38,8 @@ 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 == 0 || c1 != c2) + { if (c1 < 0xd800 || c1 >= 0xe000) { if (!(c2 < 0xd800 || c2 >= 0xe000)) @@ -56,3 +56,4 @@ u16_strcmp (const uint16_t *s1, const uint16_t *s2) /* > 0 if c1 > c2, < 0 if c1 < c2. */ } } +} diff --git a/lib/unistr/u16-strncmp.c b/lib/unistr/u16-strncmp.c index 3bba6e229b..598815dbd1 100644 --- a/lib/unistr/u16-strncmp.c +++ b/lib/unistr/u16-strncmp.c @@ -34,15 +34,12 @@ 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)) @@ -58,5 +55,6 @@ u16_strncmp (const uint16_t *s1, const uint16_t *s2, size_t n) return (int)c1 - (int)c2; /* > 0 if c1 > c2, < 0 if c1 < c2, = 0 if c1 and c2 are both 0. */ } + } return 0; } diff --git a/lib/unistr/u32-cmp.c b/lib/unistr/u32-cmp.c index e38c7e8137..1b3ae43969 100644 --- a/lib/unistr/u32-cmp.c +++ b/lib/unistr/u32-cmp.c @@ -31,18 +31,16 @@ 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. */ } + } return 0; } diff --git a/lib/unistr/u32-strcmp.c b/lib/unistr/u32-strcmp.c index d0ec7d3c87..45af280cc6 100644 --- a/lib/unistr/u32-strcmp.c +++ b/lib/unistr/u32-strcmp.c @@ -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; + 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. */ } } +} diff --git a/lib/unistr/u32-strncmp.c b/lib/unistr/u32-strncmp.c index 98461ad76c..c2a7c6dbd7 100644 --- a/lib/unistr/u32-strncmp.c +++ b/lib/unistr/u32-strncmp.c @@ -31,18 +31,16 @@ 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. */ } + } return 0; }
