Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing performance of _BinaryWriter._resizeBuffer #13456

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/dev/serializers/src/glTF/2.0/glTFExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2344,11 +2344,10 @@ export class _BinaryWriter {
*/
private _resizeBuffer(byteLength: number): ArrayBuffer {
const newBuffer = new ArrayBuffer(byteLength);
const oldUint8Array = new Uint8Array(this._arrayBuffer);
const copyOldBufferSize = Math.min(this._arrayBuffer.byteLength, byteLength);
const oldUint8Array = new Uint8Array(this._arrayBuffer, 0, copyOldBufferSize);
const newUint8Array = new Uint8Array(newBuffer);
for (let i = 0, length = newUint8Array.byteLength; i < length; ++i) {
newUint8Array[i] = oldUint8Array[i];
}
newUint8Array.set(oldUint8Array, 0);
this._arrayBuffer = newBuffer;
this._dataView = new DataView(this._arrayBuffer);

Expand Down