Skip to content

Commit

Permalink
feat: even more bits
Browse files Browse the repository at this point in the history
  • Loading branch information
yamiteru committed May 19, 2024
1 parent 9ca3f51 commit 7a3b2f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const DECODE_TYPES = [
const run = (state, type) => {
state.x = type.type;

if (state.x > 99) {
if ((state.x - 100) >> 31 === 0) {
state.x -= 100;

if (state.v.getUint8(state.o++) === 1) {
Expand Down
34 changes: 17 additions & 17 deletions src/encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ let MEMORY_VIEW = new DataView(MEMORY_POOL.buffer);
let MEMORY_LAYOUT = 0b0000000000000000000000000000000000000000000000000000000000000000;

const alloc = (c) => {
for (let i = 0; i < (64 - c); ++i) {
if((MEMORY_LAYOUT & (((1 << c) - 1) << (64 - c - i))) === 0) {
MEMORY_LAYOUT |= ((1 << c) - 1) << (64 - c - i);

return {
b: MEMORY_POOL,
v: MEMORY_VIEW,
o: 2 * i * 1000,
x: 0,
i,
c,
};
}
for (let i = 0; i < 64 - c; ++i) {
if ((MEMORY_LAYOUT & (((1 << c) - 1) << (64 - c - i))) === 0) {
MEMORY_LAYOUT |= ((1 << c) - 1) << (64 - c - i);

return {
b: MEMORY_POOL,
v: MEMORY_VIEW,
o: 2 * i * 1000,
x: 0,
i,
c,
};
}
}

MEMORY_POOL = new Uint8Array(128_000);
MEMORY_VIEW = new DataView(MEMORY_POOL.buffer);
MEMORY_LAYOUT = 0b0000000000000000000000000000000000000000000000000000000000000000;
MEMORY_LAYOUT = 0b0000000000000000000000000000000000000000000000000000000000000000;

MEMORY_LAYOUT |= ((1 << c) - 1) << (64 - c);
MEMORY_LAYOUT |= ((1 << c) - 1) << (64 - c);

return {
b: MEMORY_POOL,
Expand All @@ -41,7 +41,7 @@ const alloc = (c) => {

const free = (state) => {
if (MEMORY_VIEW === state.v) {
MEMORY_LAYOUT &= ~(((1 << state.c) - 1) << (64 - state.c - state.i));
MEMORY_LAYOUT &= ~(((1 << state.c) - 1) << (64 - state.c - state.i));
}
};

Expand Down Expand Up @@ -111,7 +111,7 @@ const ENCODE_TYPES = [
const run = (state, type, value) => {
state.x = type.type;

if (state.x > 99) {
if ((state.x - 100) >> 31 === 0) {
state.x -= 100;
state.v.setUint8(state.o++, +(value === null));

Expand Down

0 comments on commit 7a3b2f2

Please sign in to comment.