Skip to content

Commit 51b0c98

Browse files
committed
speed up truncate
1 parent 954c291 commit 51b0c98

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/lib/float32_truncate.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
* (e.g. node-webkit) that do not implement Float32Array.prototype.slice
1414
*/
1515
module.exports = function truncate(float32ArrayIn, len) {
16-
if(Float32Array.slice === undefined) {
17-
var float32ArrayOut = new Float32Array(len);
18-
for(var i = 0; i < len; i++) float32ArrayOut[i] = float32ArrayIn[i];
19-
return float32ArrayOut;
20-
}
21-
22-
return float32ArrayIn.slice(0, len);
16+
// for some reason, ES2015 Float32Array.prototype.slice takes 2x as long...
17+
// therefore we aren't checking for its existence
18+
var float32ArrayOut = new Float32Array(len);
19+
for(var i = 0; i < len; i++) float32ArrayOut[i] = float32ArrayIn[i];
20+
return float32ArrayOut;
2321
};

0 commit comments

Comments
 (0)