perf(ds): replace MD5 key hash in hashmap with FNV-1a32
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
Removes per-lookup heap allocation (MD5Buffer/kfree) in favour of a single zero-allocation FNV-1a32 pass. Drops core.enc.md5 dependency from core.ds.hashmap.
This commit is contained in:
1 parent
2159578bdf
commit
f2e5f3535a
1 file changed
+2
-13
@@ -23,7 +23,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
memory.heap,
|
memory.heap,
|
||||||
core.enc.md5,
|
core.enc.fnv1a,
|
||||||
core.strings,
|
core.strings,
|
||||||
io.syslog,
|
io.syslog,
|
||||||
debug.tracer,
|
debug.tracer,
|
||||||
@@ -64,19 +64,8 @@ procedure forEach(map : PHashMap; cb : THashForEachCb; ud : void);
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
function KeyHash(key : pchar) : uint32;
|
function KeyHash(key : pchar) : uint32;
|
||||||
var
|
|
||||||
KeyLength : uint32;
|
|
||||||
MD5_Hash : PMD5Digest;
|
|
||||||
Hash128 : puint128;
|
|
||||||
Hash32 : uint32;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
KeyLength:= StringSize(key);
|
KeyHash := Hash_FNV1a32(void(uint32(key)), StringSize(key));
|
||||||
MD5_Hash:= MD5Buffer(puint8(key), KeyLength);
|
|
||||||
Hash128:= puint128(MD5_Hash);
|
|
||||||
Hash32:= MD5To32(Hash128);
|
|
||||||
KeyHash:= Hash32;
|
|
||||||
kfree(void(MD5_Hash));
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function hashIndex(size : uint32; hash : uint32) : uint32;
|
function hashIndex(size : uint32; hash : uint32) : uint32;
|
||||||
|
|||||||
Reference in new issue
Block a user