Skip to content

Commit

Permalink
byml: Fix GrowableBuffer (#741)
Browse files Browse the repository at this point in the history
Issues introduced in 89aa596
  • Loading branch information
encounter authored Jan 3, 2025
1 parent 034dfda commit cd0f3ed
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/byml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ export function parse<T>(buffer: ArrayBufferSlice, fileType: FileType = FileType
}

class GrowableBuffer {
public buffer: ArrayBuffer;
public view: DataView;
public buffer = new ArrayBuffer();
public view = new DataView(this.buffer);
public userSize: number = 0;
public bufferSize: number = 0;

Expand All @@ -293,16 +293,13 @@ class GrowableBuffer {

if (newBufferSize > this.bufferSize) {
this.bufferSize = align(newBufferSize, this.growAmount);
this.buffer = this.buffer.transfer(newBufferSize);
this.buffer = this.buffer.transfer(this.bufferSize);
this.view = new DataView(this.buffer);
}
}

public finalize(): ArrayBuffer {
const buffer = this.buffer;
// Clear out to avoid GC.
(this as any).buffer = null;
return buffer.slice(0x00, this.userSize);
return this.buffer.transfer(this.userSize);
}
}

Expand Down

0 comments on commit cd0f3ed

Please sign in to comment.