Skip to content

Commit

Permalink
Avoid copying object fields in A.set(A other) if this == other
Browse files Browse the repository at this point in the history
  • Loading branch information
httpdigest committed Jul 23, 2023
1 parent da75414 commit ebe6de9
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/joml/Matrix2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ Matrix2d _m11(double m11) {
* @return this
*/
public Matrix2d set(Matrix2dc m) {
if (m instanceof Matrix2d) {
if (m == this)
return this;
else if (m instanceof Matrix2d) {
MemUtil.INSTANCE.copy((Matrix2d) m, this);
} else {
setMatrix2dc(m);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/joml/Matrix2f.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ Matrix2f _m11(float m11) {
* @return this
*/
public Matrix2f set(Matrix2fc m) {
if (m instanceof Matrix2f) {
if (m == this)
return this;
else if (m instanceof Matrix2f) {
MemUtil.INSTANCE.copy((Matrix2f) m, this);
} else {
setMatrix2fc(m);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/joml/Matrix3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ Matrix3d _m22(double m22) {
* @return this
*/
public Matrix3d set(Matrix3dc m) {
if (m == this)
return this;
m00 = m.m00();
m01 = m.m01();
m02 = m.m02();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/joml/Matrix3f.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ Matrix3f _m22(float m22) {
* @return this
*/
public Matrix3f set(Matrix3fc m) {
if (m == this)
return this;
return
_m00(m.m00()).
_m01(m.m01()).
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/joml/Matrix3x2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ Matrix3x2d _m21(double m21) {
* @return this
*/
public Matrix3x2d set(Matrix3x2dc m) {
if (m instanceof Matrix3x2d) {
if (m == this)
return this;
else if (m instanceof Matrix3x2d) {
MemUtil.INSTANCE.copy((Matrix3x2d) m, this);
} else {
setMatrix3x2dc(m);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/joml/Matrix3x2f.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ Matrix3x2f _m21(float m21) {
* @return this
*/
public Matrix3x2f set(Matrix3x2fc m) {
if (m instanceof Matrix3x2f) {
if (m == this)
return this;
else if (m instanceof Matrix3x2f) {
MemUtil.INSTANCE.copy((Matrix3x2f) m, this);
} else {
setMatrix3x2fc(m);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/joml/Matrix4d.java
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,8 @@ private void _identity() {
* @return this
*/
public Matrix4d set(Matrix4dc m) {
if (m == this)
return this;
return
_m00(m.m00()).
_m01(m.m01()).
Expand Down Expand Up @@ -8984,8 +8986,7 @@ else if ((properties & PROPERTY_ORTHONORMAL) != 0)
return normalGeneric(dest);
}
private Matrix4d normalOrthonormal(Matrix4d dest) {
if (dest != this)
dest.set(this);
dest.set(this);
return dest._properties(PROPERTY_AFFINE | PROPERTY_ORTHONORMAL);
}
private Matrix4d normalGeneric(Matrix4d dest) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/joml/Matrix4f.java
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ public Matrix4f identity() {
* @return this
*/
public Matrix4f set(Matrix4fc m) {
if (m == this)
return this;
//#ifdef __HAS_JVMCI__
if (JvmciCode.canUseJvmci && m instanceof Matrix4f) {
JvmciCode.__Matrix4f_set((Matrix4f) m, this);
Expand Down Expand Up @@ -12766,8 +12768,7 @@ else if ((properties & PROPERTY_ORTHONORMAL) != 0)
return normalGeneric(dest);
}
private Matrix4f normalOrthonormal(Matrix4f dest) {
if (dest != this)
dest.set(this);
dest.set(this);
return dest._properties(PROPERTY_AFFINE | PROPERTY_ORTHONORMAL);
}
private Matrix4f normalGeneric(Matrix4f dest) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/joml/Matrix4x3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ public Matrix4x3d identity() {
* @return this
*/
public Matrix4x3d set(Matrix4x3dc m) {
if (m == this)
return this;
m00 = m.m00();
m01 = m.m01();
m02 = m.m02();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/joml/Matrix4x3f.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ public Matrix4x3f identity() {
* @return this
*/
public Matrix4x3f set(Matrix4x3fc m) {
if (m == this)
return this;
m00 = m.m00();
m01 = m.m01();
m02 = m.m02();
Expand Down Expand Up @@ -7741,8 +7743,7 @@ else if ((properties & PROPERTY_ORTHONORMAL) != 0)
return normalGeneric(dest);
}
private Matrix4x3f normalOrthonormal(Matrix4x3f dest) {
if (dest != this)
dest.set(this);
dest.set(this);
return dest._properties(PROPERTY_ORTHONORMAL);
}
private Matrix4x3f normalGeneric(Matrix4x3f dest) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/joml/Vector3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ public Vector3d set(Vector4ic v) {
* @return this
*/
public Vector3d set(Vector3dc v) {
if (v == this)
return this;
this.x = v.x();
this.y = v.y();
this.z = v.z();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/joml/Vector3f.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ public Vector3f set(Vector4ic v) {
* @return this
*/
public Vector3f set(Vector3fc v) {
if (v == this)
return this;
this.x = v.x();
this.y = v.y();
this.z = v.z();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/joml/Vector4d.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ public double w() {
* @return this
*/
public Vector4d set(Vector4dc v) {
if (v == this)
return this;
this.x = v.x();
this.y = v.y();
this.z = v.z();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/joml/Vector4f.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ public float w() {
* @return this
*/
public Vector4f set(Vector4fc v) {
if (v == this)
return this;
this.x = v.x();
this.y = v.y();
this.z = v.z();
Expand Down

0 comments on commit ebe6de9

Please sign in to comment.