@type {function((TypedArray|Array |number), string, number, number=)}
(slab, types, allocator, ptr)
| 600 | // @allocator: How to allocate memory, see ALLOC_* |
| 601 | /** @type {function((TypedArray|Array<number>|number), string, number, number=)} */ |
| 602 | function allocate(slab, types, allocator, ptr) { |
| 603 | var zeroinit, size; |
| 604 | if (typeof slab === 'number') { |
| 605 | zeroinit = true; |
| 606 | size = slab; |
| 607 | } else { |
| 608 | zeroinit = false; |
| 609 | size = slab.length; |
| 610 | } |
| 611 | |
| 612 | var singleType = typeof types === 'string' ? types : null; |
| 613 | |
| 614 | var ret; |
| 615 | if (allocator == ALLOC_NONE) { |
| 616 | ret = ptr; |
| 617 | } else { |
| 618 | ret = [typeof _malloc === 'function' ? _malloc : staticAlloc, stackAlloc, staticAlloc, dynamicAlloc][allocator === undefined ? ALLOC_STATIC : allocator](Math.max(size, singleType ? 1 : types.length)); |
| 619 | } |
| 620 | |
| 621 | if (zeroinit) { |
| 622 | var stop; |
| 623 | ptr = ret; |
| 624 | assert((ret & 3) == 0); |
| 625 | stop = ret + (size & ~3); |
| 626 | for (; ptr < stop; ptr += 4) { |
| 627 | HEAP32[((ptr)>>2)]=0; |
| 628 | } |
| 629 | stop = ret + size; |
| 630 | while (ptr < stop) { |
| 631 | HEAP8[((ptr++)>>0)]=0; |
| 632 | } |
| 633 | return ret; |
| 634 | } |
| 635 | |
| 636 | if (singleType === 'i8') { |
| 637 | if (slab.subarray || slab.slice) { |
| 638 | HEAPU8.set(/** @type {!Uint8Array} */ (slab), ret); |
| 639 | } else { |
| 640 | HEAPU8.set(new Uint8Array(slab), ret); |
| 641 | } |
| 642 | return ret; |
| 643 | } |
| 644 | |
| 645 | var i = 0, type, typeSize, previousType; |
| 646 | while (i < size) { |
| 647 | var curr = slab[i]; |
| 648 | |
| 649 | type = singleType || types[i]; |
| 650 | if (type === 0) { |
| 651 | i++; |
| 652 | continue; |
| 653 | } |
| 654 | |
| 655 | if (type == 'i64') type = 'i32'; // special case: we have one i32 here, and one i32 later |
| 656 | |
| 657 | setValue(ret+i, curr, type); |
| 658 | |
| 659 | // no need to look up size unless type changes, so cache it |
no test coverage detected
searching dependent graphs…