diff options
| author | ruki <[email protected]> | 2025-10-02 22:50:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-10-02 22:50:18 +0800 |
| commit | 6377f4494967e341150f0e2bb042d3c7d8bd15c9 (patch) | |
| tree | a0e6791c22c70b58bad39d12a9c2d91d12154cad /xmake/core/base/hash.lua | |
| parent | 0938e19d1ff2711224c6e8675366fed845b28c0d (diff) | |
improve rand32
Diffstat (limited to 'xmake/core/base/hash.lua')
| -rw-r--r-- | xmake/core/base/hash.lua | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/xmake/core/base/hash.lua b/xmake/core/base/hash.lua index f08c562aa..e846ba302 100644 --- a/xmake/core/base/hash.lua +++ b/xmake/core/base/hash.lua @@ -81,11 +81,15 @@ end -- generate xxhash32 from the given file or data function hash.xxhash32(file_or_data) - local result, errors = hash.xxhash64(file_or_data) - if result then - result = result:sub(1, 8) + local hashstr, errors + if bytes.instance_of(file_or_data) then + local datasize = file_or_data:size() + local dataaddr = file_or_data:caddr() + hashstr, errors = hash._xxhash(32, dataaddr, datasize) + else + hashstr, errors = hash._xxhash(32, file_or_data) end - return result, errors + return hashstr, errors end -- generate xxhash64 from the given file or data @@ -118,11 +122,7 @@ end function hash.strhash32(str) local data = libc.ptraddr(libc.dataptr(str)) local size = #str - local result, errors = hash._xxhash(64, data, size) - if result then - result = result:sub(1, 8) - end - return result, errors + return hash._xxhash(32, data, size) end -- generate hash64 from string, e.g. "91e8ecf191e8ecf1" |
