diff --git a/minetest/png.lua b/minetest/png.lua index 627a4af..bdec662 100644 --- a/minetest/png.lua +++ b/minetest/png.lua @@ -17,6 +17,19 @@ local function bit_xor(a, b) return res end +-- Try to use `bit` library (if available) for a massive speed boost +local bit = rawget(_G, "bit") +if bit then + local bxor = bit.bxor + function bit_xor(a, b) + local res = bxor(a, b) + if res < 0 then -- convert signed to unsigned + return res + 2^32 + end + return res + end +end + local crc_table = {} for i = 0, 255 do local c = i @@ -467,4 +480,4 @@ end insert(rope, text) end) return concat(rope) -end \ No newline at end of file +end