1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vcache: use 2x wyhash.sum64_string(hk,x).hex_full(), instead of md5.sum(hk.bytes()).hex()

This commit is contained in:
Delyan Angelov 2020-10-25 09:22:31 +02:00
parent 5cb31c2c8f
commit 60cc8ac39c
2 changed files with 20 additions and 4 deletions

View File

@ -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)

View File

@ -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)