Skip to content

Commit

Permalink
perf(compile): remove table overhead for better performance (#312)
Browse files Browse the repository at this point in the history
Co-authored-by: nullchilly <nullchilly@gmail.com>
  • Loading branch information
EdenEast and nullchilly committed Feb 17, 2023
1 parent 14489df commit 4cf5680
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lua/nightfox/lib/hash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ local bitop = bit or bit32 or require("nightfox.lib.native_bit")
-- https://theartincode.stanis.me/008-djb2/
local function djb2(s)
local h = 5381
local t = { string.byte(s, 1, #s) }
for i = 1, #t do
h = bitop.lshift(h, 5) + t[i] -- h * 33 + c
for i = 1, #s do
h = bitop.lshift(h, 5) + string.byte(s, i) -- h * 33 + c
end
return h
end

-- Reference: https://github.com/catppuccin/nvim/blob/151b5f6aa74f08a707a7862519bdc38bb2b9f505/lua/catppuccin/lib/hashing.lua
-- Reference: https://github.com/catppuccin/nvim/blob/60f8f40df0db92b5715642b3ea7074380c4b7995/lua/catppuccin/lib/hashing.lua
local function hash(x)
local t = type(x)
if t == "table" then
local h = 0
for k, v in pairs(x) do
for k, v in next, x do
h = bitop.bxor(h, djb2(k .. hash(v)))
end
return h
Expand Down

0 comments on commit 4cf5680

Please sign in to comment.