Skip to content

Commit e2f87bd

Browse files
authored
Merge pull request #2454 from finetjul/speedup-vtkTexture
perf(vtktexture): speedup array data type conversion
2 parents e954c74 + 9504d92 commit e2f87bd

File tree

1 file changed

+10
-10
lines changed
  • Sources/Rendering/OpenGL/Texture

1 file changed

+10
-10
lines changed

Sources/Rendering/OpenGL/Texture/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,11 @@ function vtkOpenGLTexture(publicAPI, model) {
610610
) {
611611
for (let idx = 0; idx < data.length; idx++) {
612612
if (data[idx]) {
613-
const newArray = new Float32Array(pixCount);
614-
for (let i = 0; i < pixCount; i++) {
615-
newArray[i] = data[idx][i];
616-
}
617-
pixData.push(newArray);
613+
const dataArrayToCopy =
614+
data[idx].length > pixCount
615+
? data[idx].subarray(0, pixCount)
616+
: data[idx];
617+
pixData.push(new Float32Array(dataArrayToCopy));
618618
} else {
619619
pixData.push(null);
620620
}
@@ -629,11 +629,11 @@ function vtkOpenGLTexture(publicAPI, model) {
629629
) {
630630
for (let idx = 0; idx < data.length; idx++) {
631631
if (data[idx]) {
632-
const newArray = new Uint8Array(pixCount);
633-
for (let i = 0; i < pixCount; i++) {
634-
newArray[i] = data[idx][i];
635-
}
636-
pixData.push(newArray);
632+
const dataArrayToCopy =
633+
data[idx].length > pixCount
634+
? data[idx].subarray(0, pixCount)
635+
: data[idx];
636+
pixData.push(new Uint8Array(dataArrayToCopy));
637637
} else {
638638
pixData.push(null);
639639
}

0 commit comments

Comments
 (0)