mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-08-26 03:17:10 +01:00
Added testing option to force use untyped arrays
This commit is contained in:
parent
b13f5f1de8
commit
8ea9fc4924
1 changed files with 22 additions and 4 deletions
|
@ -1,5 +1,23 @@
|
||||||
'use strict';
|
'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, ...*/) {
|
exports.assign = function (obj /*from1, from2, from3, ...*/) {
|
||||||
var sources = Array.prototype.slice.call(arguments, 1);
|
var sources = Array.prototype.slice.call(arguments, 1);
|
||||||
while (sources.length) {
|
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
|
// Suppose, that with typed array support destination is
|
||||||
// always typed - don't check it
|
// always typed - don't check it
|
||||||
if ((typeof Uint8Array !== 'undefined') &&
|
if (typedOk() && (!isArray(src))) {
|
||||||
(!Array.isArray(src))) {
|
|
||||||
|
|
||||||
// optimize full copy
|
// optimize full copy
|
||||||
//if ((src_offs === 0) && (src.length === len)) {
|
//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) {
|
exports.arrayCreate = function (length) {
|
||||||
|
|
||||||
if ((typeof Uint8Array !== 'undefined')) {
|
if (typedOk()) {
|
||||||
return new Uint8Array(length);
|
return new Uint8Array(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +75,7 @@ exports.arrayCreate = function (length) {
|
||||||
|
|
||||||
exports.array16Create = function (length) {
|
exports.array16Create = function (length) {
|
||||||
|
|
||||||
if ((typeof Uint16Array !== 'undefined')) {
|
if (typedOk()) {
|
||||||
return new Uint16Array(length);
|
return new Uint16Array(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,5 +89,6 @@ exports.fill = function (buf, val) {
|
||||||
|
|
||||||
if (!len) { return;}
|
if (!len) { return;}
|
||||||
|
|
||||||
|
// fastest for untyped Array
|
||||||
while (--len) { buf[len] = val; }
|
while (--len) { buf[len] = val; }
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue