Move mcl_util.hash to a local function

It is probably unlikely it will be useful at other places in Mineclone2.
This commit is contained in:
Elias Åström 2021-03-16 16:57:50 +01:00
parent 2e9b3c2259
commit 6458565bf9
2 changed files with 9 additions and 9 deletions

View File

@ -405,11 +405,3 @@ function mcl_util.get_object_center(obj)
pos.y = pos.y + (ymax - ymin) / 2.0 pos.y = pos.y + (ymax - ymin) / 2.0
return pos return pos
end end
-- Compute a hash value.
function mcl_util.hash(value)
-- minetest.get_password_hash is quite fast, even if it uses a
-- cryptographic hashing function (SHA-1). It is written in C++ and it
-- is probably hard to write a faster hashing function in Lua.
return string.sub(minetest.get_password_hash("ryvnf", minetest.serialize(value)), 1, 8)
end

View File

@ -1,5 +1,13 @@
local efficiency_cache_table = {} local efficiency_cache_table = {}
-- Compute a hash value.
function compute_hash(value)
-- minetest.get_password_hash is quite fast, even if it uses a
-- cryptographic hashing function (SHA-1). It is written in C++ and it
-- is probably hard to write a faster hashing function in Lua.
return string.sub(minetest.get_password_hash("ryvnf", minetest.serialize(value)), 1, 8)
end
-- Get the efficiency groupcaps and hash for a tool and efficiency level. If -- Get the efficiency groupcaps and hash for a tool and efficiency level. If
-- this function is called repeatedly with the same values it will return data -- this function is called repeatedly with the same values it will return data
-- from a cache. -- from a cache.
@ -18,7 +26,7 @@ local function get_efficiency_groupcaps(toolname, level)
if not levelcache then if not levelcache then
levelcache = {} levelcache = {}
levelcache.values = mcl_autogroup.get_groupcaps(toolname, level) levelcache.values = mcl_autogroup.get_groupcaps(toolname, level)
levelcache.hash = mcl_util.hash(levelcache.values) levelcache.hash = compute_hash(levelcache.values)
toolcache[level] = levelcache toolcache[level] = levelcache
end end