Skip to content

Commit

Permalink
Fewer calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderOMara committed Nov 17, 2024
1 parent 52f753f commit 1679cc5
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions i24.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ export function getUint24(
byteOffset: number,
littleEndian = false,
): number {
const c = dataView.getUint8((byteOffset |= 0) + 2);
const b = dataView.getUint8(byteOffset + 1);
const a = dataView.getUint8(byteOffset);
return littleEndian ? a | b << 8 | c << 16 : a << 16 | b << 8 | c;
const b = dataView.getUint8((byteOffset |= 0) + 2);
const a = dataView.getUint16(byteOffset, littleEndian);
return littleEndian ? a | b << 16 : a << 8 | b;
}

/**
Expand Down Expand Up @@ -78,7 +77,6 @@ export function setUint24(
// Trigger native OOB exception.
dataView.setUint8(byteOffset, a);
}
dataView.setUint8(byteOffset + 2, c);
dataView.setUint8(byteOffset + 1, b);
dataView.setUint16(byteOffset + 1, b << 8 | c);
dataView.setUint8(byteOffset, a);
}

0 comments on commit 1679cc5

Please sign in to comment.