aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2014-06-06 00:32:21 +0300
committerJukka Jylänki <jujjyl@gmail.com>2014-06-06 00:32:21 +0300
commit846ee6e48346fcde8cf7672830d7524fefb308e8 (patch)
treed42dc98a90ad2ce5323bab92fce6115cc96b0cd3
parentdedf591e2be57de4f85f84569ba18581daf65a3c (diff)
Simplify typed array creation code in MEMFS.
-rw-r--r--src/library_memfs.js8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/library_memfs.js b/src/library_memfs.js
index 9bf1aa7e..24d6cc22 100644
--- a/src/library_memfs.js
+++ b/src/library_memfs.js
@@ -91,7 +91,7 @@ mergeInto(LibraryManager.library, {
#if USE_TYPED_ARRAYS == 2
if (node.contents && node.contents.subarray) {
var arr = [];
- for(var i = 0; i < node.usedBytes; ++i) arr.push(node.contents[i]);
+ for (var i = 0; i < node.usedBytes; ++i) arr.push(node.contents[i]);
return arr; // Returns a copy of the original data.
}
#endif
@@ -102,9 +102,7 @@ mergeInto(LibraryManager.library, {
// Given a file node, returns its file data converted to a typed array.
getFileDataAsTypedArray: function(node) {
if (node.contents && node.contents.subarray) return node.contents.subarray(0, node.usedBytes); // Make sure to not return excess unused bytes.
- var ta = new Uint8Array(new ArrayBuffer(node.usedBytes));
- for(var i = 0; i < node.usedBytes; ++i) ta[i] = node.contents[i];
- return ta;
+ return new Uint8Array(node.contents);
},
#endif
@@ -134,7 +132,7 @@ mergeInto(LibraryManager.library, {
newCapacity = Math.max(newCapacity, (prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2.0 : 1.125)) | 0);
if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256); // At minimum allocate 256b for each file when expanding.
var oldContents = node.contents;
- node.contents = new Uint8Array(new ArrayBuffer(newCapacity)); // Allocate new storage.
+ node.contents = new Uint8Array(newCapacity); // Allocate new storage.
if (node.usedBytes > 0) node.contents.set(oldContents.subarray(0, node.usedBytes), 0); // Copy old data over to the new storage.
return;
}