summaryrefslogtreecommitdiff
path: root/xmake/core/base/hash.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-09-30 22:45:25 +0800
committerruki <[email protected]>2025-09-30 22:45:25 +0800
commit3462dede0458b1bf755dcdb24bdc98b6f947188c (patch)
tree0a9c9c7fb33918fc51ed7b1fd39706b8f597d7df /xmake/core/base/hash.lua
parent703dec087d98946bc2ba5384d2274e588f8ee96d (diff)
improve build cache key
Diffstat (limited to 'xmake/core/base/hash.lua')
-rw-r--r--xmake/core/base/hash.lua10
1 files changed, 7 insertions, 3 deletions
diff --git a/xmake/core/base/hash.lua b/xmake/core/base/hash.lua
index b40f7b885..342b59e78 100644
--- a/xmake/core/base/hash.lua
+++ b/xmake/core/base/hash.lua
@@ -25,6 +25,7 @@ local hash = hash or {}
local io = require("base/io")
local utils = require("base/utils")
local bytes = require("base/bytes")
+local libc = require("base/libc")
-- save metatable and builtin functions
hash._md5 = hash._md5 or hash.md5
@@ -101,15 +102,18 @@ function hash.uuid(str)
return hash.uuid4(str)
end
--- TODO, we should optimize it
-- generate hash32 from string, e.g. "91e8ecf1"
function hash.strhash32(str)
- return hash.xxhash64(bytes(str)):sub(1, 8)
+ local data = libc.dataptr(str)
+ local size = #str
+ return hash._xxhash(64, data, size):sub(1, 8)
end
-- generate hash128 from string, e.g. "91e8ecf1417f4edfa574e22d7d8d204a"
function hash.strhash128(str)
- return hash.xxhash128(bytes(str))
+ local data = libc.dataptr(str)
+ local size = #str
+ return hash._xxhash(128, data, size)
end
-- return module: hash