diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-10-19 16:50:35 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-10-19 16:50:35 -0700 |
commit | 904354ec7fed6492f21571707a479951794b1a39 (patch) | |
tree | 1b61ea83651889dca7a09df1d9fddac6c560bb83 /src | |
parent | 04a6e44d823035ac7cdcdec4fa814c8e73556044 (diff) |
tweak sync xhr code a tiny bit
Diffstat (limited to 'src')
-rw-r--r-- | src/library.js | 14 | ||||
-rw-r--r-- | src/settings.js | 6 |
2 files changed, 9 insertions, 11 deletions
diff --git a/src/library.js b/src/library.js index 69642151..ff4e23a4 100644 --- a/src/library.js +++ b/src/library.js @@ -292,13 +292,11 @@ LibraryManager.library = { if (typeof XMLHttpRequest !== 'undefined') { if (!ENVIRONMENT_IS_WORKER) throw 'Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc'; - // Lazy chunked Uint8Array (implements get and length from Uint8Array). Actual getting is abstracted away for eventual reuse. var LazyUint8Array = function(chunkSize, length) { this.length = length; this.chunkSize = chunkSize; this.chunks = []; // Loaded chunks. Index is the chunk number - this.isLazyUint8Array = true; } LazyUint8Array.prototype.get = function(idx) { if (idx > this.length-1 || idx < 0) { @@ -320,7 +318,7 @@ LibraryManager.library = { var datalength = Number(xhr.getResponseHeader("Content-length")); var header; var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes"; -#if SMALL_CHUNKS +#if SMALL_XHR_CHUNKS var chunkSize = 1024; // Chunk size in bytes #else var chunkSize = 1024*1024; // Chunk size in bytes @@ -1708,13 +1706,13 @@ LibraryManager.library = { } var contents = stream.object.contents; var size = Math.min(contents.length - offset, nbyte); - if (contents.isLazyUint8Array) { - for (var i = 0; i < size; i++) { - {{{ makeSetValue('buf', 'i', 'contents.get(offset + i)', 'i8') }}} + if (contents.byteLength) { + for (var i = 0; i < size; i++) { // typed array + {{{ makeSetValue('buf', 'i', 'contents[offset + i]', 'i8') }}} } } else { - for (var i = 0; i < size; i++) { - {{{ makeSetValue('buf', 'i', 'contents[offset + i]', 'i8') }}} + for (var i = 0; i < size; i++) { // LazyUint8Array from sync binary XHR + {{{ makeSetValue('buf', 'i', 'contents.get(offset + i)', 'i8') }}} } } bytesRead += size; diff --git a/src/settings.js b/src/settings.js index 4017ad98..a6c11448 100644 --- a/src/settings.js +++ b/src/settings.js @@ -255,9 +255,9 @@ var WARN_ON_UNDEFINED_SYMBOLS = 0; // If set to 1, we will warn on any undefined // the existing buildsystem), and (2) functions might be // implemented later on, say in --pre-js -var SMALL_CHUNKS = 0; // Use small chunk size for binary synchronous XHR's in Web Workers. - // Used for testing. - // See test_chunked_synchronous_xhr in runner.py and library.js. +var SMALL_XHR_CHUNKS = 0; // Use small chunk size for binary synchronous XHR's in Web Workers. + // Used for testing. + // See test_chunked_synchronous_xhr in runner.py and library.js. // Compiler debugging options var DEBUG_TAGS_SHOWING = []; |