mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-26 02:17:34 +09:00
JS optimisations pt.1
This commit is contained in:
parent
c27a24f779
commit
6cc90c7009
31 changed files with 867 additions and 107 deletions
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -230,8 +230,17 @@ uint32_t
|
|||
HashKnownLength(const T* aStr, size_t aLength)
|
||||
{
|
||||
uint32_t hash = 0;
|
||||
for (size_t i = 0; i < aLength; i++) {
|
||||
hash = AddToHash(hash, aStr[i]);
|
||||
while (aLength >= 4) {
|
||||
hash = AddToHash(hash, aStr[0]);
|
||||
hash = AddToHash(hash, aStr[1]);
|
||||
hash = AddToHash(hash, aStr[2]);
|
||||
hash = AddToHash(hash, aStr[3]);
|
||||
aStr += 4;
|
||||
aLength -= 4;
|
||||
}
|
||||
while (aLength) {
|
||||
hash = AddToHash(hash, *aStr++);
|
||||
--aLength;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue