Skip to content

Commit 0211c7d

Browse files
committed
refactor(BinaryWriter): optimize buffer manipulation using copyWithin
1 parent 736f022 commit 0211c7d

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

packages/protobuf/src/wire/binary-encoding.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ export class BinaryWriter {
151151
const tmp: number[] = [];
152152
varint32write(len, tmp);
153153
this.ensureCapacity(tmp.length);
154-
for (let i = this.pos - 1; i >= forkPos; i--) {
155-
this.buffer[i + tmp.length] = this.buffer[i];
156-
}
154+
this.buffer.copyWithin(forkPos + tmp.length, forkPos, this.pos);
157155
for (let i = 0; i < tmp.length; i++) {
158156
this.buffer[forkPos + i] = tmp[i];
159157
}

0 commit comments

Comments
 (0)