зеркало из https://github.com/mozilla/pluotsorbet.git
zero primitive arrays with memset
This commit is contained in:
Родитель
589bae2764
Коммит
a4839a0b69
1
Makefile
1
Makefile
|
@ -96,7 +96,6 @@ MAIN_JS_SRCS = \
|
||||||
polyfill/find.js \
|
polyfill/find.js \
|
||||||
polyfill/findIndex.js \
|
polyfill/findIndex.js \
|
||||||
polyfill/fround.js \
|
polyfill/fround.js \
|
||||||
polyfill/TypedArray.js \
|
|
||||||
blackBox.js \
|
blackBox.js \
|
||||||
timer.js \
|
timer.js \
|
||||||
util.js \
|
util.js \
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
// Per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray,
|
|
||||||
// "all typed array prototypes (TypedArray.prototype) have %TypedArray%.prototype as their [[Prototype]]."
|
|
||||||
// So it doesn't matter which TypedArray constructor we use to dereference
|
|
||||||
// the prototype.
|
|
||||||
var proto = Object.getPrototypeOf(Int8Array.prototype);
|
|
||||||
|
|
||||||
if (!("fill" in proto)) {
|
|
||||||
proto.fill = function(value, start, end) {
|
|
||||||
if ((typeof start) === "undefined") {
|
|
||||||
start = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((typeof end) === "undefined") {
|
|
||||||
end = this.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = start; i < end; i++) {
|
|
||||||
this[i] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
})();
|
|
|
@ -299,7 +299,7 @@ tests.push(function() {
|
||||||
ASM._forceCollection();
|
ASM._forceCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
ok(!zeroedOut, "gcMallocAtomic doesn't zero-out allocated memory");
|
ok(zeroedOut, "gcMallocAtomic does zero-out allocated memory");
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
@ -326,7 +326,7 @@ tests.push(function() {
|
||||||
ASM._forceCollection();
|
ASM._forceCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
ok(zeroedOut, "newArray does zero-out allocated memory");
|
ok(zeroedOut, "newIntArray does zero-out allocated memory");
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1227,8 +1227,6 @@ interface Int8Array extends ArrayBufferView {
|
||||||
* @param end The index of the end of the array.
|
* @param end The index of the end of the array.
|
||||||
*/
|
*/
|
||||||
subarray(begin: number, end?: number): Int8Array;
|
subarray(begin: number, end?: number): Int8Array;
|
||||||
|
|
||||||
fill(value: number, start?: number, end?: number): void;
|
|
||||||
}
|
}
|
||||||
declare var Int8Array: {
|
declare var Int8Array: {
|
||||||
prototype: Int8Array;
|
prototype: Int8Array;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
// Formatting: Printing longs.
|
// Formatting: Printing longs.
|
||||||
// printf("L: %" PRId64 ", R: %" PRId64, *l, *r);
|
// printf("L: %" PRId64 ", R: %" PRId64, *l, *r);
|
||||||
|
@ -69,7 +70,9 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t gcMallocAtomic(int32_t size) {
|
uintptr_t gcMallocAtomic(int32_t size) {
|
||||||
return (uintptr_t)GC_MALLOC_ATOMIC(size);
|
uintptr_t ptr = (uintptr_t)GC_MALLOC_ATOMIC(size);
|
||||||
|
memset((void*)ptr, 0, size);
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gcRegisterDisappearingLink(uintptr_t p, uintptr_t objAddr) {
|
void gcRegisterDisappearingLink(uintptr_t p, uintptr_t objAddr) {
|
||||||
|
|
|
@ -1346,11 +1346,6 @@ module J2ME {
|
||||||
|
|
||||||
if (elementClassInfo instanceof PrimitiveClassInfo) {
|
if (elementClassInfo instanceof PrimitiveClassInfo) {
|
||||||
addr = ASM._gcMallocAtomic(Constants.ARRAY_HDR_SIZE + size * (<PrimitiveArrayClassInfo>arrayClassInfo).bytesPerElement);
|
addr = ASM._gcMallocAtomic(Constants.ARRAY_HDR_SIZE + size * (<PrimitiveArrayClassInfo>arrayClassInfo).bytesPerElement);
|
||||||
|
|
||||||
// Zero-out memory because GC_MALLOC_ATOMIC doesn't do it automatically.
|
|
||||||
var off = Constants.ARRAY_HDR_SIZE + addr;
|
|
||||||
var end = off + size * (<PrimitiveArrayClassInfo>arrayClassInfo).bytesPerElement;
|
|
||||||
i8.fill(0, off, end);
|
|
||||||
} else {
|
} else {
|
||||||
// We need to hold an integer to define the length of the array
|
// We need to hold an integer to define the length of the array
|
||||||
// and *size* references.
|
// and *size* references.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче