[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.
- [libmicrohttpd2] branch master updated (cdd4c1f -> a71f9db), Admin, 2025/06/13
- [libmicrohttpd2] 09/21: mhd_str: added 8 bit -> 2 xdigits one-pass encoding, Admin, 2025/06/13
- [libmicrohttpd2] 11/21: mhd_str: optimised caseless comparisons and case transformations,
Admin <=
- [libmicrohttpd2] 13/21: parse_http_std_method(): optimised, Admin, 2025/06/13
- [libmicrohttpd2] 21/21: perf_replies: added response sizes 8 MiB and 101 MiB, Admin, 2025/06/13
- [libmicrohttpd2] 02/21: bootstrap: make sure that pre-commit hook really used, Admin, 2025/06/13
- [libmicrohttpd2] 01/21: conn_data_send.c: fixed large sending, added some asserts, Admin, 2025/06/13
- [libmicrohttpd2] 04/21: xdigittovalue(): optimised., Admin, 2025/06/13
- [libmicrohttpd2] 18/21: Renamed test_postprocessor -> test_postparser to match API naming, Admin, 2025/06/13
- [libmicrohttpd2] 16/21: configure: minor check improvement, Admin, 2025/06/13
- [libmicrohttpd2] 12/21: mhd_locks: added W32 implementation based on SRW locks (and minor improvements), Admin, 2025/06/13
- [libmicrohttpd2] 10/21: configure: added release build linker flags, Admin, 2025/06/13
- [libmicrohttpd2] 15/21: POST parser: improved parsing performance by storing complete delimiter instead of boundary, Admin, 2025/06/13