Skip to content

Commit

Permalink
perf(soa): update attribValues() impl
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Oct 16, 2019
1 parent 53581f1 commit 786a02f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/soa/src/soa.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
assert,
ILength,
SIZEOF,
TypedArray,
typedArray
typedArray,
TYPEDARRAY_CTORS
} from "@thi.ng/api";
import { ReadonlyVec, Vec } from "@thi.ng/vectors";
import { SOAAttribSpec, SOASpecs, SOATuple } from "./api";
Expand Down Expand Up @@ -36,12 +38,14 @@ export class SOA<K extends string> implements ILength {
this.ensureAttrib(id);
this.ensureIndex(from);
this.ensureIndex(to, from, this.length);
const buf = this.buffers[id];
const { size, stride } = this.specs[id];
let { size, stride, type } = this.specs[id];
const ctor = TYPEDARRAY_CTORS[type!];
const buf = this.buffers[id].buffer;
stride! *= SIZEOF[type!];
from *= stride!;
to *= stride!;
for (; from < to; from += stride!) {
yield buf.subarray(from, from + size!);
yield new ctor(buf, from, size!);
}
}

Expand Down

0 comments on commit 786a02f

Please sign in to comment.