JS optimisations pt.1

This commit is contained in:
wuggy 2026-09-18 13:11:49 -07:00
commit 6cc90c7009
31 changed files with 867 additions and 107 deletions

View file

@ -20,7 +20,17 @@ HashBytes(const void* aBytes, size_t aLength)
/* Walk word by word. */
size_t i = 0;
for (; i < aLength - (aLength % sizeof(size_t)); i += sizeof(size_t)) {
const size_t wordLength = aLength - (aLength % sizeof(size_t));
const size_t doubleWordLength = wordLength - (wordLength % (2 * sizeof(size_t)));
for (; i < doubleWordLength; i += 2 * sizeof(size_t)) {
size_t data0;
size_t data1;
memcpy(&data0, b + i, sizeof(data0));
memcpy(&data1, b + i + sizeof(data0), sizeof(data1));
hash = AddToHash(hash, data0, sizeof(data0));
hash = AddToHash(hash, data1, sizeof(data1));
}
for (; i < wordLength; i += sizeof(size_t)) {
/* Do an explicitly unaligned load of the data. */
size_t data;
memcpy(&data, b + i, sizeof(size_t));