aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clox/src/table.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/clox/src/table.c b/clox/src/table.c
index 2405397..040b277 100644
--- a/clox/src/table.c
+++ b/clox/src/table.c
@@ -20,7 +20,7 @@ void freeTable(Table *table) {
}
static Entry *findEntry(Entry *entries, int capacity, ObjString *key) {
- uint32_t index = key->hash % capacity;
+ uint32_t index = key->hash & (capacity - 1);
Entry *tombstone = NULL;
for (;;) {
@@ -39,7 +39,7 @@ static Entry *findEntry(Entry *entries, int capacity, ObjString *key) {
return entry;
}
- index = (index + 1) % capacity;
+ index = (index + 1) & (capacity - 1);
}
}
@@ -124,7 +124,7 @@ ObjString *tableFindString(Table *table, const char *chars, int length,
if (table->count == 0)
return NULL;
- uint32_t index = hash % table->capacity;
+ uint32_t index = hash & (table->capacity - 1);
for (;;) {
Entry *entry = &table->entries[index];
if (entry->key == NULL) {
@@ -137,7 +137,7 @@ ObjString *tableFindString(Table *table, const char *chars, int length,
return entry->key;
}
- index = (index + 1) % table->capacity;
+ index = (index + 1) & (table->capacity - 1);
}
}