Skip to content

Commit

Permalink
fix(msgpack): fix buffer growth logic
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 19, 2024
1 parent 5ffdea3 commit b601018
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/msgpack/src/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ export const serialize = (src: any, opts: Partial<EncodeOpts> = {}) => {
let pos = 0;

const ensure = () => {
if (pos > buf.length) {
let newLength = buf.length;
if (pos > newLength) {
while (pos > newLength) newLength <<= 1;
const curr = buf;
buf = new Uint8Array(curr.length * 2);
buf = new Uint8Array(newLength);
view = new DataView(buf.buffer);
buf.set(curr);
}
Expand Down

0 comments on commit b601018

Please sign in to comment.