Skip to content

Commit

Permalink
Documented need of parenthesis in htonl and htons
Browse files Browse the repository at this point in the history
  • Loading branch information
dpino committed Sep 7, 2017
1 parent 93b4818 commit 7601615
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7601615

Please sign in to comment.