switch to reused float array where possible

This commit is contained in:
2025-01-22 23:21:36 -06:00
parent 7d7b92678b
commit cb60d22549
6 changed files with 28 additions and 32 deletions
@@ -1,9 +1,9 @@
import chunk from '../chunk';
const floatArray = new Float32Array(3);
export default (x: number, y: number, z: number): Uint8Array => {
const buf = new DataView(new ArrayBuffer(12));
buf.setFloat32(0, x, true);
buf.setFloat32(4, y, true);
buf.setFloat32(8, z, true);
return chunk(0x0004, new Uint8Array(buf.buffer), false);
floatArray[0] = x;
floatArray[1] = y;
floatArray[2] = z;
return chunk(0x0004, new Uint8Array(floatArray.buffer), false);
};
+5 -6
View File
@@ -1,10 +1,9 @@
import chunk from '../chunk';
const floatArray = new Float32Array(3);
export default (x: number, y: number, z: number): Uint8Array => {
const buf = new DataView(new ArrayBuffer(12));
buf.setFloat32(0, x, true);
buf.setFloat32(4, y, true);
buf.setFloat32(8, z, true);
return chunk(0x0002, new Uint8Array(buf.buffer), false);
floatArray[0] = x;
floatArray[1] = y;
floatArray[2] = z;
return chunk(0x0002, new Uint8Array(floatArray.buffer), false);
};
+5 -6
View File
@@ -1,11 +1,10 @@
import chunk from '../chunk';
const floatArray = new Float32Array(3);
export default (x: number, y: number, z: number): Uint8Array => {
const buf = new DataView(new ArrayBuffer(12));
floatArray[0] = x;
floatArray[1] = y;
floatArray[2] = z;
buf.setFloat32(0, x, true);
buf.setFloat32(4, y, true);
buf.setFloat32(8, z, true);
return chunk(0x0000, new Uint8Array(buf.buffer), false);
return chunk(0x0000, new Uint8Array(floatArray.buffer), false);
};
@@ -1,11 +1,10 @@
import chunk from '../chunk';
const floatArray = new Float32Array(3);
export default (x: number, y: number, z: number): Uint8Array => {
const buf = new DataView(new ArrayBuffer(12));
floatArray[0] = x;
floatArray[1] = y;
floatArray[2] = z;
buf.setFloat32(0, x, true);
buf.setFloat32(4, y, true);
buf.setFloat32(8, z, true);
return chunk(0x0001, new Uint8Array(buf.buffer), false);
return chunk(0x0001, new Uint8Array(floatArray.buffer), false);
};
@@ -1,7 +1,7 @@
import chunk from '../chunk';
const floatArray = new Float32Array(1);
export default (validity: number): Uint8Array => {
const buf = new DataView(new ArrayBuffer(4));
buf.setFloat32(0, validity, true);
return chunk(0x0003, new Uint8Array(buf.buffer), false);
floatArray[0] = validity;
return chunk(0x0003, new Uint8Array(floatArray.buffer), false);
};
@@ -1,11 +1,10 @@
import chunk from '../chunk';
const floatArray = new Float32Array(3);
export default (x: number, y: number, z: number): Uint8Array => {
const buf = new DataView(new ArrayBuffer(12));
floatArray[0] = x;
floatArray[1] = y;
floatArray[2] = z;
buf.setFloat32(0, x, true);
buf.setFloat32(4, y, true);
buf.setFloat32(8, z, true);
return chunk(0x0005, new Uint8Array(buf.buffer), false);
return chunk(0x0005, new Uint8Array(floatArray.buffer), false);
};