From f5f08167777ccb2dd5a95cb8c0f8af0b49de9656 Mon Sep 17 00:00:00 2001 From: theraven Date: Tue, 19 Apr 2011 10:54:00 +0000 Subject: [PATCH] Make the selector hash depend on the types as well as the name - should reduce hash collisions between typed and untyped versions. --- selector_table.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/selector_table.c b/selector_table.c index 0c0922d..70687d1 100644 --- a/selector_table.c +++ b/selector_table.c @@ -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; }