From 76016155e51591240ec8331d9799ab10b4f00634 Mon Sep 17 00:00:00 2001 From: Diego Pino Garcia Date: Thu, 7 Sep 2017 08:23:33 +0000 Subject: [PATCH] Documented need of parenthesis in htonl and htons --- src/core/lib.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/lib.lua b/src/core/lib.lua index e573c224f4..2b997122ea 100644 --- a/src/core/lib.lua +++ b/src/core/lib.lua @@ -374,6 +374,11 @@ if ffi.abi("be") then function htons(b) return b end else -- htonl is unsigned, matching the C version and expectations. + -- Wrapping the return call in parenthesis avoids the compiler to do + -- a tail call optimization. In LuaJIT when the number of successive + -- tail calls is higher than the loop unroll threshold, the + -- compilation of a trace is aborted. If the trace was long that + -- can result in poor performance. function htonl(b) return (tonumber(cast('uint32_t', bswap(b)))) end function htons(b) return (rshift(bswap(b), 16)) end end