mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-09 17:36:23 +00:00
use raw bitwise instead of buffers
This commit is contained in:
parent
2b1c0100bf
commit
7cdf3464a1
1 changed files with 5 additions and 10 deletions
|
@ -21,14 +21,14 @@ import { Devs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
|
|
||||||
// Compute a 64-bit FNV-1a hash of the passed data
|
// Compute a 64-bit FNV-1a hash of the passed data
|
||||||
function hash(data: ArrayBuffer) {
|
function hash(id: bigint) {
|
||||||
const fnvPrime = 1099511628211n;
|
const fnvPrime = 1099511628211n;
|
||||||
const offsetBasis = 14695981039346656037n;
|
const offsetBasis = 14695981039346656037n;
|
||||||
|
|
||||||
let result = offsetBasis;
|
let result = offsetBasis;
|
||||||
for (const byte of new Uint8Array(data)) {
|
for (let i = 7n; i >= 0n; i--) {
|
||||||
result ^= BigInt(byte);
|
result ^= (id >> (8n * i)) & 0xffn;
|
||||||
result = (result * fnvPrime) % 2n**32n;
|
result = (result * fnvPrime) % 2n ** 32n;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -36,12 +36,7 @@ function hash(data: ArrayBuffer) {
|
||||||
|
|
||||||
// Calculate a CSS color string based on the user ID
|
// Calculate a CSS color string based on the user ID
|
||||||
function calculateNameColorForUser(id: bigint) {
|
function calculateNameColorForUser(id: bigint) {
|
||||||
const idBuffer = new ArrayBuffer(8);
|
const idHash = hash(id);
|
||||||
{
|
|
||||||
const idView = new DataView(idBuffer);
|
|
||||||
idView.setBigUint64(0, id);
|
|
||||||
}
|
|
||||||
const idHash = hash(idBuffer);
|
|
||||||
|
|
||||||
return `hsl(${idHash % 360n}, 100%, ${settings.store.lightness}%)`;
|
return `hsl(${idHash % 360n}, 100%, ${settings.store.lightness}%)`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue