Skip to content

Commit

Permalink
perf(vectors): minor optimization for 0-index Vec2/3/4 accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Oct 13, 2019
1 parent 187ebdf commit a7c561d
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions packages/vectors/src/internal/accessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@ export const declareIndex = (
strided = true,
defNumeric = true
) => {
const get = strided
? function() {
return this.buf[this.offset + idx * this.stride];
}
: function() {
return this.buf[this.offset + idx];
};
const set = strided
? function(n: number) {
this.buf[this.offset + idx * this.stride] = n;
}
: function(n: number) {
this.buf[this.offset + idx] = n;
};

const get =
idx > 0
? strided
? function() {
return this.buf[this.offset + idx * this.stride];
}
: function() {
return this.buf[this.offset + idx];
}
: function() {
return this.buf[this.offset];
};
const set =
idx > 0
? strided
? function(n: number) {
this.buf[this.offset + idx * this.stride] = n;
}
: function(n: number) {
this.buf[this.offset + idx] = n;
}
: function(n: number) {
this.buf[this.offset] = n;
};
defNumeric &&
Object.defineProperty(proto, idx, {
get,
Expand Down

0 comments on commit a7c561d

Please sign in to comment.