Bug 983577 - Improvements to parallel and sequential map for TypedObject. r=shu

This commit is contained in:
Lars T Hansen 2014-03-21 09:05:37 -04:00
parent 69cce4574a
commit 98b3628c4b

View File

@ -1302,11 +1302,16 @@ function MapTypedSeqImpl(inArray, depth, outputType, func) {
var inGrainTypeIsComplex = !TypeDescrIsSimpleType(inGrainType);
var outGrainTypeIsComplex = !TypeDescrIsSimpleType(outGrainType);
var inPointer = new TypedObjectPointer(inGrainType, inArray, 0);
var outPointer = new TypedObjectPointer(outGrainType, result, 0);
// Specialize for depth=1 non-complex types, for now. May disappear if
// optimization becomes good enough or be generalized beyond depth=1.
var inUnitSize = DESCR_SIZE(inGrainType);
var outUnitSize = DESCR_SIZE(outGrainType);
var isDepth1Simple = depth == 1 && !(inGrainTypeIsComplex || outGrainTypeIsComplex);
var inPointer = isDepth1Simple ? null : new TypedObjectPointer(inGrainType, inArray, 0);
var outPointer = isDepth1Simple ? null : new TypedObjectPointer(outGrainType, result, 0);
var inUnitSize = isDepth1Simple ? 0 : DESCR_SIZE(inGrainType);
var outUnitSize = isDepth1Simple ? 0 : DESCR_SIZE(outGrainType);
// Bug 956914: add additional variants for depth = 2, 3, etc.
@ -1331,6 +1336,16 @@ function MapTypedSeqImpl(inArray, depth, outputType, func) {
return result;
}
function DoMapTypedSeqDepth1Simple(inArray, totalLength, func, result) {
for (var i = 0; i < totalLength; i++) {
var r = func(inArray[i], i, inArray, undefined);
if (r !== undefined)
result[i] = r;
}
return result;
}
function DoMapTypedSeqDepthN() {
var indices = new Uint32Array(depth);
@ -1356,12 +1371,13 @@ function MapTypedSeqImpl(inArray, depth, outputType, func) {
return result;
}
if (depth == 1) {
return DoMapTypedSeqDepth1();
} else {
return DoMapTypedSeqDepthN();
}
if (isDepth1Simple)
return DoMapTypedSeqDepth1Simple(inArray, totalLength, func, result);
if (depth == 1)
return DoMapTypedSeqDepth1();
return DoMapTypedSeqDepthN();
}
// Implements |map| and |from| methods for typed |inArray|.