From 3308ce812d041a6b78cd79f23d37270093f5e372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Tue, 16 Mar 2021 16:57:50 +0100 Subject: [PATCH] Move mcl_util.hash to a local function It is probably unlikely it will be useful at other places in Mineclone2. --- mods/CORE/mcl_util/init.lua | 8 -------- mods/ITEMS/mcl_enchanting/efficiency.lua | 10 +++++++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index bac919a8..6c63c21a 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -405,11 +405,3 @@ function mcl_util.get_object_center(obj) pos.y = pos.y + (ymax - ymin) / 2.0 return pos 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 diff --git a/mods/ITEMS/mcl_enchanting/efficiency.lua b/mods/ITEMS/mcl_enchanting/efficiency.lua index afb97bfc..d4b06e5f 100644 --- a/mods/ITEMS/mcl_enchanting/efficiency.lua +++ b/mods/ITEMS/mcl_enchanting/efficiency.lua @@ -1,5 +1,13 @@ 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 -- this function is called repeatedly with the same values it will return data -- from a cache. @@ -18,7 +26,7 @@ local function get_efficiency_groupcaps(toolname, level) if not levelcache then levelcache = {} levelcache.values = mcl_autogroup.get_groupcaps(toolname, level) - levelcache.hash = mcl_util.hash(levelcache.values) + levelcache.hash = compute_hash(levelcache.values) toolcache[level] = levelcache end