diff options
author | ubq323 <ubq323@ubq323.website> | 2024-06-21 02:46:15 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-06-21 02:46:15 +0100 |
commit | 671645c370498955eb101695bd9099bf4caf5aea (patch) | |
tree | 119db5228fceaa1e340a2f30017885b5377a2068 | |
parent | 5298940fc7798455d701d075b910e0545d3f6048 (diff) |
minor optimization
-rw-r--r-- | com.c | 1 | ||||
-rw-r--r-- | ht.c | 8 | ||||
-rw-r--r-- | val.c | 4 |
3 files changed, 8 insertions, 5 deletions
@@ -175,6 +175,7 @@ int main() { chunk_wbc(S, &ch, OP_PRINT); chunk_wbc(S, &ch, OP_RET); + puts("compile done"); return runvm(S); } @@ -24,15 +24,17 @@ Ht ht_new() { } static HtEntry *find(HtEntry *b, size_t cap, ObjString *k) { - size_t ix = k->hash % cap; + // cap is guaranteed to be power of 2 + size_t mask = cap - 1; + size_t ix = k->hash & mask; if (cap == 0) return NULL; for (;;) { HtEntry *ent = &b[ix]; // XXX tombstones - if (ent->k == k || ent->k == NULL) { + if (ent->k == NULL || ent->k == k) { return ent; } - ix = (ix+1)%cap; + ix = (ix+1) & mask; } } @@ -76,8 +76,8 @@ void println_val(Val v) { } bool is_truthy(Val v) { - if (IS_NIL(v) || ( IS_BOOL(v) && AS_BOOL(v) == false)) - return false; + if (IS_BOOL(v)) return AS_BOOL(v); + if (IS_NIL(v)) return false; return true; } |