mirror of
https://github.com/darlinghq/darling-libobjc2.git
synced 2025-03-03 06:06:05 +00:00
Make the selector hash depend on the types as well as the name - should reduce
hash collisions between typed and untyped versions.
This commit is contained in:
parent
c6556fd230
commit
f5f0816777
@ -189,8 +189,24 @@ static inline uint32_t hash_selector(const void *s)
|
||||
{
|
||||
hash = hash * 33 + c;
|
||||
}
|
||||
// FIXME: We might want to make the hash dependent on the types, since not
|
||||
// doing so increases the number of potential hash collisions.
|
||||
#ifdef TYPE_DEPENDENT_DISPATCH
|
||||
// We can't use all of the values in the type encoding for the hash,
|
||||
// because our equality test is a bit more complex than simple string
|
||||
// encoding (for example, * and ^C have to be considered equivalent, since
|
||||
// they are both used as encodings for C strings in different situations)
|
||||
if ((str = sel_getType_np(sel)))
|
||||
{
|
||||
while((c = (uint32_t)*str++))
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '0'...'9':
|
||||
case '@': case 'i': case 'I': case 'l': case 'L':
|
||||
hash = hash * 33 + c;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user