Skip to content

Commit

Permalink
refactor(malloc): migrate & re-use types from thi.ng/api
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Oct 7, 2019
1 parent b72e664 commit 12898f0
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions packages/malloc/src/wrap.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
import { IObjectOf, Type } from "@thi.ng/api";

export type TypedArrayConstructor =
| Uint8ArrayConstructor
| Uint8ClampedArrayConstructor
| Int8ArrayConstructor
| Uint16ArrayConstructor
| Int16ArrayConstructor
| Uint32ArrayConstructor
| Int32ArrayConstructor
| Float32ArrayConstructor
| Float64ArrayConstructor;

export const TYPEDARRAY_CTORS: IObjectOf<TypedArrayConstructor> = {
[Type.U8]: Uint8Array,
[Type.U8C]: Uint8ClampedArray,
[Type.I8]: Int8Array,
[Type.U16]: Uint16Array,
[Type.I16]: Int16Array,
[Type.U32]: Uint32Array,
[Type.I32]: Int32Array,
[Type.F32]: Float32Array,
[Type.F64]: Float64Array
};
import { Type, TYPEDARRAY_CTORS } from "@thi.ng/api";

export const wrap = (type: Type, buf: ArrayBuffer, addr: number, num: number) =>
new TYPEDARRAY_CTORS[type](buf, addr, num);

0 comments on commit 12898f0

Please sign in to comment.