diff options
| author | ruki <[email protected]> | 2025-10-07 00:27:40 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-10-06 20:49:26 +0800 |
| commit | 75a5ae1bfbd0570819c9cab6e623f2f26db2e8a2 (patch) | |
| tree | cfed77a9075e2dc55d87890eb21b11004b0ce95f | |
| parent | dc3f8642301976871a1510b2bda77b94b2984cac (diff) | |
use rand64 first
| -rw-r--r-- | tests/modules/hash/test.lua | 5 | ||||
| -rw-r--r-- | xmake/core/base/hash.lua | 3 | ||||
| -rw-r--r-- | xmake/plugins/project/cmake/cmakelists.lua | 4 | ||||
| -rw-r--r-- | xmake/rules/c++/unity_build/unity_build.lua | 2 |
4 files changed, 6 insertions, 8 deletions
diff --git a/tests/modules/hash/test.lua b/tests/modules/hash/test.lua index 6bfe89fcd..06722fd9d 100644 --- a/tests/modules/hash/test.lua +++ b/tests/modules/hash/test.lua @@ -1,10 +1,7 @@ function test_rand32(t) local set = {} - for i = 1, 1000000 do + for i = 1, 1000 do local r = hash.rand32() - if set[r] then - print("i: %d, r: %s, o: %s", i, r, set[r]) - end t:require(set[r] == nil) set[r] = r end diff --git a/xmake/core/base/hash.lua b/xmake/core/base/hash.lua index 9d7ca40ed..b03b6d2a1 100644 --- a/xmake/core/base/hash.lua +++ b/xmake/core/base/hash.lua @@ -145,8 +145,9 @@ function hash.strhash128(str) end -- generate random32 hash +-- @note it is easy to trigger hash conflicts function hash.rand32() - if hash._rand32 then + if false then --hash._rand32 then return hash._rand32() else return hash.strhash32(tostring(math.random())) diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index a339a654e..a4d8361e1 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -1074,7 +1074,7 @@ function _add_target_link_libraries(cmakelists, target, outputdir) local has_links = #target:objectfiles() > objectfiles_set:size() - local key = target:name() .. "_" .. hash.rand32() + local key = target:name() .. "_" .. hash.rand64() if has_links then cmakelists:print("add_library(target_objectfiles_%s OBJECT IMPORTED GLOBAL)", key) cmakelists:print("set_property(TARGET target_objectfiles_%s PROPERTY IMPORTED_OBJECTS", key) @@ -1244,7 +1244,7 @@ function _add_target_custom_commands_for_batchcmds(cmakelists, target, outputdir -- -- @see https://gitlab.kitware.com/cmake/cmake/-/issues/17802 -- - local key = target:name() .. "_" .. hash.rand32() + local key = target:name() .. "_" .. hash.rand64() cmakelists:print("add_custom_command(OUTPUT output_%s", key) for _, cmd in ipairs(cmds) do local command = _get_command_string(cmd, outputdir) diff --git a/xmake/rules/c++/unity_build/unity_build.lua b/xmake/rules/c++/unity_build/unity_build.lua index 3df2d75b4..d5f5b060c 100644 --- a/xmake/rules/c++/unity_build/unity_build.lua +++ b/xmake/rules/c++/unity_build/unity_build.lua @@ -36,7 +36,7 @@ function _merge_unityfile(target, sourcefile_unity, sourcefiles, opt) sourcefile_unity = path.absolute(sourcefile_unity) sourcefile = path.relative(sourcefile, path.directory(sourcefile_unity)) if uniqueid then - unityfile:print("#define %s %s", uniqueid, "unity_" .. hash.rand32()) + unityfile:print("#define %s %s", uniqueid, "unity_" .. hash.rand64()) end unityfile:print("#include \"%s\"", sourcefile) if uniqueid then |
