From 60cc8ac39c137f3ddd33a7fb37dd04890e0f4c62 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 25 Oct 2020 09:22:31 +0200 Subject: [PATCH] vcache: use 2x wyhash.sum64_string(hk,x).hex_full(), instead of md5.sum(hk.bytes()).hex() --- vlib/builtin/int.v | 14 ++++++++++++++ vlib/v/pref/vcache.v | 10 ++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index 538971818e..03af49c1f0 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -368,6 +368,20 @@ pub fn (nn byteptr) str() string { return u64(nn).hex() } +// pub fn (nn byte) hex_full() string { return u64_to_hex(nn, 2) } +// pub fn (nn i8) hex_full() string { return u64_to_hex(byte(nn), 2) } +// pub fn (nn u16) hex_full() string { return u64_to_hex(nn, 4) } +// pub fn (nn i16) hex_full() string { return u64_to_hex(u16(nn), 4) } +// pub fn (nn u32) hex_full() string { return u64_to_hex(nn, 8) } +// pub fn (nn int) hex_full() string { return u64_to_hex(u32(nn), 8) } +pub fn (nn u64) hex_full() string { + return u64_to_hex(nn, 16) +} + +// pub fn (nn i64) hex_full() string { return u64_to_hex(u64(nn), 16) } +// pub fn (nn any_int) hex_full() string { return u64_to_hex(nn, 16) } +// pub fn (nn voidptr) hex_full() string { return u64_to_hex(nn, 16) } +// pub fn (nn byteptr) hex_full() string { return u64_to_hex(nn, 16) } pub fn (b byte) str() string { // TODO //return int(b).str_l(7) diff --git a/vlib/v/pref/vcache.v b/vlib/v/pref/vcache.v index ac9f689007..eabaf258ef 100644 --- a/vlib/v/pref/vcache.v +++ b/vlib/v/pref/vcache.v @@ -1,7 +1,7 @@ module pref import os -import crypto.md5 +import hash // Using a 2 level cache, ensures a more even distribution of cache entries, // so there will not be cramped folders that contain many thousands of them. @@ -47,10 +47,12 @@ pub fn (mut cm CacheManager) key2cpath(key string) string { mut cpath := cm.k2cpath[key] if cpath == '' { hk := cm.vopts + key - hash := md5.sum(hk.bytes()).hex() - prefix := hash[0..2] + a := hash.sum64_string(hk, 5).hex_full() + b := hash.sum64_string(hk, 7).hex_full() + khash := a + b + prefix := khash[0..2] cprefix_folder := os.join_path(cm.basepath, prefix) - cpath = os.join_path(cprefix_folder, hash) + cpath = os.join_path(cprefix_folder, khash) if !os.is_dir(cprefix_folder) { os.mkdir_all(cprefix_folder) os.chmod(cprefix_folder, 0o777)