Skip to content

Commit 297e8f0

Browse files
author
Joel Dice
committed
don't calculate the index in hashMapInsert until it's needed
1 parent b6ce0ca commit 297e8f0

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/util.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ void
340340
hashMapInsert(Thread* t, object map, object key, object value,
341341
uint32_t (*hash)(Thread*, object))
342342
{
343-
// note that we reinitialize the array and index variables whenever
344-
// an allocation (and thus possibly a collection) occurs, in case
345-
// the array changes due to a table resize.
343+
// note that we reinitialize the array variable whenever an
344+
// allocation (and thus possibly a collection) occurs, in case the
345+
// array changes due to a table resize.
346346

347347
PROTECT(t, map);
348348

@@ -378,12 +378,11 @@ hashMapInsert(Thread* t, object map, object key, object value,
378378
array = hashMapArray(t, map);
379379
}
380380

381-
unsigned index = h & (arrayLength(t, array) - 1);
382-
383381
object n = makeTriple(t, k, value, 0);
384382

385383
array = hashMapArray(t, map);
386-
index = h & (arrayLength(t, array) - 1);
384+
385+
unsigned index = h & (arrayLength(t, array) - 1);
387386

388387
set(t, n, TripleThird, arrayBody(t, array, index));
389388
set(t, array, ArrayBody + (index * BytesPerWord), n);

0 commit comments

Comments
 (0)