From e0648730121453ac4f8b7c2affece8cfef5c2ea3 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Fri, 21 Jul 2023 18:11:20 +0200 Subject: [PATCH] PNG reader: Use `bit` library if available --- minetest/png.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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