Open CanadaHonk opened 1 month ago
Also, while maybe it's obvious, it's probably better to do this with two loops in order to avoid extra branching, i.e.
const str: u32[] = a;
const str2: u32[] = b;
const end = str.length - str.length % 4;
for (let i = 0; i != end; i += 4) {
if (str[i] !== str2[i]) break
}
// etc. read the last characters in a traditional way
Also, since our strings can read off the end anyways, it might be better to "pad" the ends of strings so they are aligned to u32s, skipping the modulo and second loop in the above example
From a memory perspective, individual characters do not matter. We can read/write
u32
chunks while length > 4 instead of individualu8
s/u16
s.Places where this could be done: