1.0.0 • Published 8 years ago
babel-plugin-multidimensional-array v1.0.0
babel-plugin-multidimensional-array
Fast multidimensional typed arrays with a nice syntax.
Typed arrays are awesome, but sometimes you want a multidimensional array. You can do it with arrays of (arrays of...) typed arrays, but accessing or writing data to nested array objects is slow.
One way to fix this is by using a single flattened typed array, and hand calculating the offset where the data is for every access. But that is tedious. This babel plugin takes care of it for you. Just define your local variables or function arguments with dimensions, and accesses will be transformed to compute the correct offset.
Example
Compiles this:
let x[2][3] = new Uint8Array([1,2,3,4,5,6]);
x[1][2] = 42;
into:
let x = new Uint8Array([1,2,3,4,5,6]);
x[5] = 42;
Function arguments are also supported, as are non-constant dimensions:
function test(x[a][b], y) {
x[1][y] = 4;
}
compiles to:
function test(x, y) {
x[y + b * 1] = 4;
}
Licence
MIT
1.0.0
8 years ago