gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd2] 11/21: mhd_str: optimised caseless comparisons and case


From: Admin
Subject: [libmicrohttpd2] 11/21: mhd_str: optimised caseless comparisons and case transformations
Date: Fri, 13 Jun 2025 23:38:19 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd2.

commit ae5c45e446df498d237a8026eab0b8a1aa741b01
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
AuthorDate: Thu Jun 12 22:07:24 2025 +0200

    mhd_str: optimised caseless comparisons and case transformations
---
 src/mhd2/mhd_str.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/mhd2/mhd_str.c b/src/mhd2/mhd_str.c
index 8e72508..1136cb8 100644
--- a/src/mhd2/mhd_str.c
+++ b/src/mhd2/mhd_str.c
@@ -157,7 +157,7 @@ isasciialnum (char c)
 MHD_static_inline_ MHD_FN_CONST_ char
 toasciilower (char c)
 {
-  return isasciiupper (c) ? (c - 'A' + 'a') : c;
+  return isasciiupper (c) ? (char) (0x20u | (unsigned char) c) : c;
 }
 
 
@@ -173,7 +173,7 @@ toasciilower (char c)
 MHD_static_inline_ MHD_FN_CONST_ char
 toasciiupper (char c)
 {
-  return isasciilower (c) ? (c - 'a' + 'A') : c;
+  return isasciilower (c) ? (char) ((~0x20u) & (unsigned char) c) : c;
 }
 
 
@@ -809,12 +809,14 @@ uint8totwoxdigits (uint8_t v)
  * @return boolean 'true' if chars are caseless equal, false otherwise
  */
 MHD_static_inline_ MHD_FN_CONST_ bool
-charsequalcaseless (const char c1, const char c2)
+charsequalcaseless (char c1, char c2)
 {
-  return ( (c1 == c2) ||
-           (((c1 - 'A' + 'a') == c2) ?
-            isasciiupper (c1) :
-            ((c1 == (c2 - 'A' + 'a')) && isasciiupper (c2))) );
+  if (c1 == c2)
+    return true;
+  /* Fold case on both sides */
+  c1 = ((char) (~0x20u & (unsigned char) c1));
+  c2 = ((char) (~0x20u & (unsigned char) c2));
+  return (c1 == c2) && isasciiupper (c1);
 }
 
 
@@ -962,11 +964,10 @@ static const char map_value_to_xdigit[16] =
  * @param c2 the second char to compare
  * @return boolean 'true' if chars are caseless equal, false otherwise
  */
-#  define charsequalcaseless(c1, c2) \
+#define charsequalcaseless(c1, c2) \
         ( ((c1) == (c2)) || \
-          ((((c1) - 'A' + 'a') == (c2)) ? \
-           isasciiupper (c1) : \
-           (((c1) == ((c2) - 'A' + 'a')) && isasciiupper (c2))) )
+          (((0x20u | (unsigned char) c1) == (0x20u | (unsigned char) c2)) && \
+           toasciilower (((char) (0x20u | (unsigned char) c2)))) )
 
 #endif /* !HAVE_INLINE_FUNCS */
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]