Skip to content

Commit d77e59e

Browse files
funny-falcontmm1
authored andcommitted
a bit better initial position
1 parent b4c0a46 commit d77e59e

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

vm_method.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct cache_entry {
2828

2929
#define METHOD_ENTRY(entry) ((rb_method_entry_t*)((entry)->me & ~1))
3030
#define COLLISION(entry) ((entry).me & 1)
31+
#define HASH(id) (id ^ (id >> 3))
3132

3233
static void rb_mcache_resize(struct rb_meth_cache *cache);
3334
static void
@@ -39,7 +40,7 @@ rb_mcache_insert(struct rb_meth_cache *cache, ID id, uintptr_t me, VALUE defined
3940
rb_mcache_resize(cache);
4041
}
4142
mask = cache->capa - 1;
42-
pos = (id >> 3) & mask;
43+
pos = HASH(id) & mask;
4344

4445
ent = cache->entries;
4546
if (ent[pos].mid == 0) {
@@ -100,7 +101,7 @@ rb_mcache_find(struct rb_meth_cache *cache, ID id)
100101
{
101102
struct cache_entry *ent = cache->entries;
102103
int mask = cache->capa - 1;
103-
int pos = (id >> 3) & mask;
104+
int pos = HASH(id) & mask;
104105
int dlt;
105106
if (ent[pos].mid == id) return ent + pos;
106107
if (!COLLISION(ent[pos])) return NULL;

0 commit comments

Comments
 (0)