Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
apacheli committed May 8, 2021
1 parent c749037 commit 930ca38
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/packer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const bigint = (e: E, int: bigint) => {
const index = add(e, 4);
u8(e, int < 0n ? 1 : 0);
let i = 0;
for (; int > 0; i++, int >>= 8n) {
u8(e, Number(int & 0xFFn));
for (; int > 0; i++, int /= 256n) {
u8(e, Number(int % 256n));
}
e.view.setUint32(index, i);
};
Expand Down
4 changes: 2 additions & 2 deletions lib/unpacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const unpack_string = (e: E, len: number) => {
const unpack_large_big = (e: E, digits: number) => {
const sign = u8(e);
let int = 0n;
for (let i = 0, b = 1n; i < digits; i++, b <<= 8n) {
for (let i = 0, b = 1n; i < digits; i++, b *= 256n) {
int += BigInt(u8(e)) * b;
}
int = sign ? -int : int;
Expand All @@ -68,7 +68,7 @@ const unpack_large_big = (e: E, digits: number) => {
const unpack_small_big = (e: E, digits: number) => {
const sign = u8(e);
let int = 0;
for (let i = 0, b = 1; i < digits; i++, b <<= 8) {
for (let i = 0, b = 1; i < digits; i++, b *= 256) {
int += u8(e) * b;
}
return sign ? -int : int;
Expand Down

0 comments on commit 930ca38

Please sign in to comment.