Skip to content

Commit c7194ee

Browse files
committed
perf: improve constructor performance for initial data.
Set buffer's initial size to initial data's length if data's length is greater than initial size or default size.
1 parent ee8a0e2 commit c7194ee

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/dynamicBuffer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ export class DynamicBuffer {
162162
this.size = this.DefaultInitialSize;
163163
}
164164

165+
if (data && data.length > this.size) {
166+
this.size = data.length;
167+
}
168+
165169
if (this.size < 0 || this.size > constants.MAX_LENGTH) {
166170
throw new Error('Invalid buffer size');
167171
}

0 commit comments

Comments
 (0)