Bug 7741 – getHash inconsistent for const(char)[] vs. char[] and string
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-20T06:39:00Z
Last change time
2013-08-17T12:06:02Z
Assigned to
nobody
Creator
hsteoh
Comments
Comment #0 by hsteoh — 2012-03-20T06:39:30Z
Code:
char[] a = "abc".dup;
const(char)[] b = "abc";
string c = "abc";
writeln(typeid(a).getHash(&a)); // 12914
writeln(typeid(b).getHash(&b)); // 8503969683799911018
writeln(typeid(c).getHash(&c)); // 12914
It appears that char[] and string (==immutable(char)[]) have getHash implemented in rt.typeinfo.ti_Ad.TypeInfo_Aa, which has its own hashing algorithm, whereas const(char)[] just uses object.TypeInfo_Array.getHash, which calls rt.util.hash.hashOf.