]> git.kaiwu.me - nginx.git/commitdiff
Improved ngx_quic_build_int() code and readability.
authorSergey Kandaurov <pluknet@nginx.com>
Wed, 22 Apr 2020 11:52:16 +0000 (14:52 +0300)
committerSergey Kandaurov <pluknet@nginx.com>
Wed, 22 Apr 2020 11:52:16 +0000 (14:52 +0300)
The function now generates somewhat shorter assembler after inlining.

src/event/ngx_event_quic_transport.c

index 1a2cada3547d885fe507cdeaa1d980f1f9966538..19e7ba305cb3325c4660543e271a989ca5996836 100644 (file)
@@ -238,29 +238,23 @@ static void
 ngx_quic_build_int(u_char **pos, uint64_t value)
 {
     u_char      *p;
-    ngx_uint_t   len;//, len2;
+    ngx_uint_t   bits, len;
 
     p = *pos;
-    len = 0;
+    bits = 0;
 
-    while (value >> ((1 << len) * 8 - 2)) {
-        len++;
+    while (value >> ((8 << bits) - 2)) {
+        bits++;
     }
 
-    *p = len << 6;
+    len = (1 << bits);
 
-//    len2 =
-    len = (1 << len);
-    len--;
-    *p |= value >> (len * 8);
-    p++;
-
-    while (len) {
-        *p++ = value >> ((len-- - 1) * 8);
+    while (len--) {
+        *p++ = value >> (len * 8);
     }
 
+    **pos |= bits << 6;
     *pos = p;
-//    return len2;
 }