aboutsummaryrefslogtreecommitdiff
path: root/tools/file_packager.py
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-08-27 14:17:38 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-08-27 14:17:38 -0700
commit3b2b7341aad1fb098b4a90a88ee8ee271b61e39a (patch)
tree77aa96f974c4bedd16d163fc8c9a96ae7ae43bfb /tools/file_packager.py
parent8c249ab4d5c786395ab6e7043e95a0a2387d4461 (diff)
copy the entire datafile in one chunk into the heap, avoiding one malloc per file, but at the cost of not being able to free them
Diffstat (limited to 'tools/file_packager.py')
-rw-r--r--tools/file_packager.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/tools/file_packager.py b/tools/file_packager.py
index 2871f1ed..8a1f1ba5 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -344,14 +344,7 @@ if has_preloaded:
},
send: function() {},
onload: function() {
- var data = this.byteArray.subarray(this.start, this.end);
- var size = this.end - this.start;
- var ptr = Module['_malloc'](size); // XXX leaked if a preload plugin replaces with new data
- Module['HEAPU8'].set(data, ptr);
- var arrayBuffer = Module['HEAPU8'].subarray(ptr, ptr + size);
- assert(arrayBuffer, 'Loading file ' + name + ' failed');
- var byteArray = !arrayBuffer.subarray ? new Uint8Array(arrayBuffer) : arrayBuffer;
-
+ var byteArray = this.byteArray.subarray(this.start, this.end);
if (this.crunched) {
var ddsHeader = byteArray.subarray(0, 128);
var that = this;
@@ -419,7 +412,12 @@ for file_ in data_files:
if has_preloaded:
# Get the big archive and split it up
- use_data = ' DataRequest.prototype.byteArray = byteArray;\n'
+ use_data = '''
+ // copy the entire loaded file into a spot in the heap. Files will refer to slices in that. They cannot be freed though.
+ var ptr = Module['_malloc'](byteArray.length);
+ Module['HEAPU8'].set(byteArray, ptr);
+ DataRequest.prototype.byteArray = Module['HEAPU8'].subarray(ptr, ptr+byteArray.length);
+'''
for file_ in data_files:
if file_['mode'] == 'preload':
use_data += ' DataRequest.prototype.requests["%s"].onload();\n' % (file_['dstpath'])