comparison src/event/ngx_event_quic_transport.c @ 8351:dd84c9cef75b quic

Improved ngx_quic_build_int() code and readability. The function now generates somewhat shorter assembler after inlining.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 22 Apr 2020 14:52:16 +0300
parents e0abe17a2878
children 42198f77ac85
comparison
equal deleted inserted replaced
8350:47dac6e0521a 8351:dd84c9cef75b
236 236
237 static void 237 static void
238 ngx_quic_build_int(u_char **pos, uint64_t value) 238 ngx_quic_build_int(u_char **pos, uint64_t value)
239 { 239 {
240 u_char *p; 240 u_char *p;
241 ngx_uint_t len;//, len2; 241 ngx_uint_t bits, len;
242 242
243 p = *pos; 243 p = *pos;
244 len = 0; 244 bits = 0;
245 245
246 while (value >> ((1 << len) * 8 - 2)) { 246 while (value >> ((8 << bits) - 2)) {
247 len++; 247 bits++;
248 } 248 }
249 249
250 *p = len << 6; 250 len = (1 << bits);
251 251
252 // len2 = 252 while (len--) {
253 len = (1 << len); 253 *p++ = value >> (len * 8);
254 len--; 254 }
255 *p |= value >> (len * 8); 255
256 p++; 256 **pos |= bits << 6;
257
258 while (len) {
259 *p++ = value >> ((len-- - 1) * 8);
260 }
261
262 *pos = p; 257 *pos = p;
263 // return len2;
264 } 258 }
265 259
266 260
267 u_char * 261 u_char *
268 ngx_quic_error_text(uint64_t error_code) 262 ngx_quic_error_text(uint64_t error_code)