aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/library.js10
-rw-r--r--src/preamble.js37
2 files changed, 25 insertions, 22 deletions
diff --git a/src/library.js b/src/library.js
index fe6ae0fb..b74b9744 100644
--- a/src/library.js
+++ b/src/library.js
@@ -2715,7 +2715,11 @@ LibraryManager.library = {
if (arg) {
copiedString = String_copy(arg);
if (precisionSet && copiedString.length > precision) {
+#if USE_TYPED_ARRAYS == 2
+ copiedString = copiedString.subarray(0, precision);
+#else
copiedString = copiedString.slice(0, precision);
+#endif
}
} else {
copiedString = intArrayFromString('(null)', true);
@@ -2725,7 +2729,13 @@ LibraryManager.library = {
ret.push(' '.charCodeAt(0));
}
}
+#if USE_TYPED_ARRAYS == 2
+ for (var i = 0; i < copiedString.length; i++) {
+ ret.push(copiedString[i]);
+ }
+#else
ret = ret.concat(copiedString);
+#endif
if (flagLeftAlign) {
while (copiedString.length < width--) {
ret.push(' '.charCodeAt(0));
diff --git a/src/preamble.js b/src/preamble.js
index 997e5ab3..fde9e2cf 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -723,38 +723,31 @@ function exitRuntime() {
// Copies a list of num items on the HEAP into a
-// a normal JavaScript array of numbers
+// a JavaScript array of numbers (normal array in TA0 or TA1,
+// typed array in TA2)
function Array_copy(ptr, num) {
#if USE_TYPED_ARRAYS == 1
// TODO: In the SAFE_HEAP case, do some reading here, for debugging purposes - currently this is an 'unnoticed read'.
return Array.prototype.slice.call(IHEAP.subarray(ptr, ptr+num)); // Make a normal array out of the typed 'view'
// Consider making a typed array here, for speed?
-#endif
+#else
#if USE_TYPED_ARRAYS == 2
- return Array.prototype.slice.call(HEAP8.subarray(ptr, ptr+num)); // Make a normal array out of the typed 'view'
- // Consider making a typed array here, for speed?
-#endif
+ var end = ptr+num;
+ if (end <= HEAPU8.length) {
+ return new Uint8Array(HEAPU8.subarray(ptr, end));
+ } else {
+ // we fill with zeros after the end of the array
+ var ret = new Uint8Array(end - ptr);
+ ret.set(HEAPU8.subarray(ptr, end));
+ return ret;
+ }
+#else
return HEAP.slice(ptr, ptr+num);
+#endif
+#endif
}
Module['Array_copy'] = Array_copy;
-#if USE_TYPED_ARRAYS
-// Copies a list of num items on the HEAP into a
-// JavaScript typed array.
-function TypedArray_copy(ptr, num, offset /*optional*/) {
- // TODO: optimize this!
- if (offset === undefined) {
- offset = 0;
- }
- var arr = new Uint8Array(num - offset);
- for (var i = offset; i < num; ++i) {
- arr[i - offset] = {{{ makeGetValue('ptr', 'i', 'i8') }}};
- }
- return arr.buffer;
-}
-Module['TypedArray_copy'] = TypedArray_copy;
-#endif
-
function String_len(ptr) {
var i = 0;
while ({{{ makeGetValue('ptr', 'i', 'i8') }}}) i++; // Note: should be |!= 0|, technically. But this helps catch bugs with undefineds