benilla-re systems structs docs

computesizes

function · lua · primitive

Address
0x6fab00 · 143 bytes, up to 0x6fab8e
Signature
void __fastcall (int32_t *nums, int32_t ntotal, int32_t *narray, int32_t *nhash)
Meaning
Chooses the array size so that at least half of its slots are in use
Confidence
verified, proof two
Finding
lua/object#choosing-the-array-size
Test
lua::computesizes_difftest

Finding: Choosing the array size in lua: objects and tables

computesizes picks the array part as upstream 5.0 does, not 5.1. It walks the slices nums[i], the integer keys in (2^(i-1), 2^i], adding each nonempty one to the running count a, and takes 2^i as the size, holding a keys, when after adding a >= 2^(i-1); an empty slice never moves the size. It stops once a reaches the integer key count *narray or *narray < 2^(i-1). Keys 3 and 4 alone give an array of 4; keys 1, 2 and 5 give 2. The array is 2^n, or 0 with no size taken, and the hash part gets ntotal less the keys the array holds.

The derivation is in the doc.

Callers 1

Callees 0

None by a direct call or jump.

Calls and jumps by a bare address, from tables/calls.tsv.