Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMD port, plus bugfixes #1

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ Using it
Simplest way is just to call jszlib_uncompress. Takes an ArrayBuffer, returns an ArrayBuffer,
throws an exception if something breaks. You can also use a ZStream class which behaves
much like ZStream from jzlib. This might be useful if you need to uncompress partial data --
some kinds of streaming network protocol, for instance -- but is overkill for most applications.
some kinds of streaming network protocol, for instance -- but is overkill for most applications.
48 changes: 48 additions & 0 deletions arrayCopy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
define([],
function() {

var testArray;
try {
testArray = new Uint8Array(1);
} catch (x) {}
var hasSlice = false; /* (typeof testArray.slice === 'function'); */ // Chrome slice performance is so dire that we're currently not using it...

function arrayCopy(src, srcOffset, dest, destOffset, count) {
if (count == 0) {
return;
}
if (!src) {
throw "Undef src";
} else if (!dest) {
throw "Undef dest";
}

if (srcOffset == 0 && count == src.length) {
arrayCopy_fast(src, dest, destOffset);
} else if ( src.subarray ) {
arrayCopy_fast(src.subarray(srcOffset, srcOffset + count), dest, destOffset);
} else if (src.BYTES_PER_ELEMENT == 1 && count > 100) {
arrayCopy_fast(new Uint8Array(src.buffer, src.byteOffset + srcOffset, count), dest, destOffset);
} else {
arrayCopy_slow(src, srcOffset, dest, destOffset, count);
}

}

function arrayCopy_slow(src, srcOffset, dest, destOffset, count) {

// dlog('_slow call: srcOffset=' + srcOffset + '; destOffset=' + destOffset + '; count=' + count);

for (var i = 0; i < count; ++i) {
dest[destOffset + i] = src[srcOffset + i];
}
}

function arrayCopy_fast(src, dest, destOffset) {
dest.set(src, destOffset);
}


return arrayCopy;

});
Loading