Skip to content

Commit

Permalink
Improve performance of Matrix3.set/get(column, row) using Unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
httpdigest committed May 7, 2020
1 parent 14033e6 commit d024b83
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 365 deletions.
186 changes: 4 additions & 182 deletions src/org/joml/Matrix3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -3507,47 +3507,7 @@ public Matrix3d setColumn(int column, double x, double y, double z) throws Index
}

public double get(int column, int row) {
switch (column) {
case 0:
switch (row) {
case 0:
return m00;
case 1:
return m01;
case 2:
return m02;
default:
break;
}
break;
case 1:
switch (row) {
case 0:
return m10;
case 1:
return m11;
case 2:
return m12;
default:
break;
}
break;
case 2:
switch (row) {
case 0:
return m20;
case 1:
return m21;
case 2:
return m22;
default:
break;
}
break;
default:
break;
}
throw new IllegalArgumentException();
return MemUtil.INSTANCE.get(this, column, row);
}

/**
Expand All @@ -3562,100 +3522,11 @@ public double get(int column, int row) {
* @return this
*/
public Matrix3d set(int column, int row, double value) {
switch (column) {
case 0:
switch (row) {
case 0:
this.m00 = value;
return this;
case 1:
this.m01 = value;
return this;
case 2:
this.m02 = value;
return this;
default:
break;
}
break;
case 1:
switch (row) {
case 0:
this.m10 = value;
return this;
case 1:
this.m11 = value;
return this;
case 2:
this.m12 = value;
return this;
default:
break;
}
break;
case 2:
switch (row) {
case 0:
this.m20 = value;
return this;
case 1:
this.m21 = value;
return this;
case 2:
this.m22 = value;
return this;
default:
break;
}
break;
default:
break;
}
throw new IllegalArgumentException();
return MemUtil.INSTANCE.set(this, column, row, value);
}

public double getRowColumn(int row, int column) {
switch (row) {
case 0:
switch (column) {
case 0:
return m00;
case 1:
return m01;
case 2:
return m02;
default:
break;
}
break;
case 1:
switch (column) {
case 0:
return m10;
case 1:
return m11;
case 2:
return m12;
default:
break;
}
break;
case 2:
switch (column) {
case 0:
return m20;
case 1:
return m21;
case 2:
return m22;
default:
break;
}
break;
default:
break;
}
throw new IllegalArgumentException();
return MemUtil.INSTANCE.get(this, column, row);
}

/**
Expand All @@ -3670,56 +3541,7 @@ public double getRowColumn(int row, int column) {
* @return this
*/
public Matrix3d setRowColumn(int row, int column, double value) {
switch (row) {
case 0:
switch (column) {
case 0:
this.m00 = value;
return this;
case 1:
this.m01 = value;
return this;
case 2:
this.m02 = value;
return this;
default:
break;
}
break;
case 1:
switch (column) {
case 0:
this.m10 = value;
return this;
case 1:
this.m11 = value;
return this;
case 2:
this.m12 = value;
return this;
default:
break;
}
break;
case 2:
switch (column) {
case 0:
this.m20 = value;
return this;
case 1:
this.m21 = value;
return this;
case 2:
this.m22 = value;
return this;
default:
break;
}
break;
default:
break;
}
throw new IllegalArgumentException();
return MemUtil.INSTANCE.set(this, column, row, value);
}

/**
Expand Down
Loading

0 comments on commit d024b83

Please sign in to comment.