gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] 01/02: MHD_uint32_to_strx(): rewritten for readability a


From: gnunet
Subject: [libmicrohttpd] 01/02: MHD_uint32_to_strx(): rewritten for readability and minor optimization
Date: Thu, 04 Nov 2021 14:16:12 +0100

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 61b997d944dc45a698850191ba6679c12898005f
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Wed Nov 3 16:43:56 2021 +0300

    MHD_uint32_to_strx(): rewritten for readability and minor optimization
---
 src/microhttpd/mhd_str.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index 0526a1a5..6c07a574 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -1203,25 +1203,27 @@ MHD_uint32_to_strx (uint32_t val,
                     char *buf,
                     size_t buf_size)
 {
-  char *chr; /**< pointer to the current printed digit */
-  int digit_pos = 7; /** zero-based, digit position in @a 'val' */
+  size_t o_pos = 0; /**< position of the output character */
+  int digit_pos = 8; /** zero-based, digit position in @a 'val' */
   int digit;
 
-  chr = buf;
-  digit = (int) (((val) >> (4 * digit_pos)) & 0xf);
-
   /* Skip leading zeros */
-  while ((0 == digit) && (0 != digit_pos))
-    digit = (int) (((val) >> (4 * --digit_pos)) & 0xf);
+  do
+  {
+    digit_pos--;
+    digit = (int) (val >> 28);
+    val <<= 4;
+  } while ((0 == digit) && (0 != digit_pos));
 
-  while (0 != buf_size)
+  while (o_pos < buf_size)
   {
-    *chr = (digit <= 9) ? ('0' + (char) digit) : ('A' + (char) digit - 10);
-    chr++;
-    buf_size--;
+    buf[o_pos++] = (digit <= 9) ? ('0' + (char) digit) :
+                   ('A' + (char) digit - 10);
     if (0 == digit_pos)
-      return (size_t) (chr - buf);
-    digit = (int) (((val) >> (4 * --digit_pos)) & 0xf);
+      return o_pos;
+    digit_pos--;
+    digit = (int) (val >> 28);
+    val <<= 4;
   }
   return 0; /* The buffer is too small */
 }

-- 
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]