Added testing option to force use untyped arrays

master
Vitaly Puzrin 2014-02-14 07:31:53 +04:00
rodzic b13f5f1de8
commit 8ea9fc4924
1 zmienionych plików z 22 dodań i 4 usunięć

Wyświetl plik

@ -1,5 +1,23 @@
'use strict';
var TYPED_OK = (typeof Uint8Array !== 'undefined') &&
(typeof Uint16Array !== 'undefined') &&
(typeof Uint32Array !== 'undefined');
var _toString = Function.prototype.call.bind(Object.prototype.toString);
var isArray = Array.isArray || function (obj) { return _toString(obj) === '[object Array]'; };
// For debug/testing. Set true to force use untyped arrays
exports.forceUntyped = false;
function typedOk() {
return TYPED_OK && !exports.forceUntyped;
}
exports.typedOk = typedOk;
exports.assign = function (obj /*from1, from2, from3, ...*/) {
var sources = Array.prototype.slice.call(arguments, 1);
while (sources.length) {
@ -25,8 +43,7 @@ exports.arraySet = function (dest, src, src_offs, len, dest_offs) {
// Suppose, that with typed array support destination is
// always typed - don't check it
if ((typeof Uint8Array !== 'undefined') &&
(!Array.isArray(src))) {
if (typedOk() && (!isArray(src))) {
// optimize full copy
//if ((src_offs === 0) && (src.length === len)) {
@ -47,7 +64,7 @@ exports.arraySet = function (dest, src, src_offs, len, dest_offs) {
exports.arrayCreate = function (length) {
if ((typeof Uint8Array !== 'undefined')) {
if (typedOk()) {
return new Uint8Array(length);
}
@ -58,7 +75,7 @@ exports.arrayCreate = function (length) {
exports.array16Create = function (length) {
if ((typeof Uint16Array !== 'undefined')) {
if (typedOk()) {
return new Uint16Array(length);
}
@ -72,5 +89,6 @@ exports.fill = function (buf, val) {
if (!len) { return;}
// fastest for untyped Array
while (--len) { buf[len] = val; }
};