changeset 9640:65d7696fb58a

Value: tidy up generated `hashCode()' and `equals()' methods a bit
author Bernhard Urban <bernhard.urban@jku.at>
date Fri, 10 May 2013 21:03:53 +0200
parents fde5ccbab3a3
children 5e8299154973
files graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Register.java graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterValue.java graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/StackSlot.java graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Value.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMonitorValue.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/Variable.java
diffstat 7 files changed, 46 insertions(+), 175 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Register.java	Fri May 10 23:27:19 2013 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Register.java	Fri May 10 21:03:53 2013 +0200
@@ -96,29 +96,16 @@
 
         @Override
         public int hashCode() {
-            return 31 + ((name == null) ? 0 : name.hashCode());
+            return 23 + name.hashCode();
         }
 
         @Override
         public boolean equals(Object obj) {
-            if (this == obj) {
-                return true;
-            }
-            if (obj == null) {
-                return false;
-            }
-            if (getClass() != obj.getClass()) {
-                return false;
+            if (obj instanceof RegisterCategory) {
+                RegisterCategory other = (RegisterCategory) obj;
+                return name.equals(other.name);
             }
-            RegisterCategory other = (RegisterCategory) obj;
-            if (name == null) {
-                if (other.name != null) {
-                    return false;
-                }
-            } else if (!name.equals(other.name)) {
-                return false;
-            }
-            return true;
+            return false;
         }
     }
 
@@ -219,48 +206,21 @@
 
     @Override
     public int hashCode() {
-        final int prime = 31;
+        final int prime = 17;
         int result = 1;
         result = prime * result + encoding;
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + name.hashCode();
         result = prime * result + number;
-        result = prime * result + ((registerCategory == null) ? 0 : registerCategory.hashCode());
+        result = prime * result + registerCategory.hashCode();
         return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        Register other = (Register) obj;
-        if (encoding != other.encoding) {
-            return false;
+        if (obj instanceof Register) {
+            Register other = (Register) obj;
+            return encoding == other.encoding && name.equals(other.name) && number == other.number && registerCategory.equals(registerCategory);
         }
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
-            return false;
-        }
-        if (number != other.number) {
-            return false;
-        }
-        if (registerCategory == null) {
-            if (other.registerCategory != null) {
-                return false;
-            }
-        } else if (!registerCategory.equals(other.registerCategory)) {
-            return false;
-        }
-        return true;
+        return false;
     }
-
 }
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterValue.java	Fri May 10 23:27:19 2013 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterValue.java	Fri May 10 21:03:53 2013 +0200
@@ -58,28 +58,15 @@
 
     @Override
     public int hashCode() {
-        return 31 * super.hashCode() + ((reg == null) ? 0 : reg.hashCode());
+        return 29 * super.hashCode() + reg.hashCode();
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!super.equals(obj)) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
+        if (obj instanceof RegisterValue) {
+            RegisterValue other = (RegisterValue) obj;
+            return super.equals(obj) && reg.equals(other.reg);
         }
-        RegisterValue other = (RegisterValue) obj;
-        if (reg == null) {
-            if (other.reg != null) {
-                return false;
-            }
-        } else if (!reg.equals(other.reg)) {
-            return false;
-        }
-        return true;
+        return false;
     }
 }
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/StackSlot.java	Fri May 10 23:27:19 2013 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/StackSlot.java	Fri May 10 21:03:53 2013 +0200
@@ -118,7 +118,7 @@
 
     @Override
     public int hashCode() {
-        final int prime = 31;
+        final int prime = 37;
         int result = super.hashCode();
         result = prime * result + (addFrameSize ? 1231 : 1237);
         result = prime * result + offset;
@@ -127,22 +127,10 @@
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!super.equals(obj)) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
+        if (obj instanceof StackSlot) {
+            StackSlot other = (StackSlot) obj;
+            return super.equals(obj) && addFrameSize == other.addFrameSize && offset == other.offset;
         }
-        StackSlot other = (StackSlot) obj;
-        if (addFrameSize != other.addFrameSize) {
-            return false;
-        }
-        if (offset != other.offset) {
-            return false;
-        }
-        return true;
+        return false;
     }
 }
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Value.java	Fri May 10 23:27:19 2013 +0200
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Value.java	Fri May 10 21:03:53 2013 +0200
@@ -81,35 +81,19 @@
 
     @Override
     public int hashCode() {
-        final int prime = 31;
+        final int prime = 41;
         int result = 1;
-        result = prime * result + ((kind == null) ? 0 : kind.hashCode());
-        result = prime * result + ((platformKind == null) ? 0 : platformKind.hashCode());
+        result = prime * result + kind.hashCode();
+        result = prime * result + platformKind.hashCode();
         return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
+        if (obj instanceof Value) {
+            Value other = (Value) obj;
+            return kind.equals(other.kind) && platformKind.equals(platformKind);
         }
-        Value other = (Value) obj;
-        if (kind != other.kind) {
-            return false;
-        }
-        if (platformKind == null) {
-            if (other.platformKind != null) {
-                return false;
-            }
-        } else if (!platformKind.equals(other.platformKind)) {
-            return false;
-        }
-        return true;
+        return false;
     }
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMonitorValue.java	Fri May 10 23:27:19 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMonitorValue.java	Fri May 10 21:03:53 2013 +0200
@@ -66,43 +66,20 @@
 
     @Override
     public int hashCode() {
-        final int prime = 31;
+        final int prime = 43;
         int result = super.hashCode();
         result = prime * result + (eliminated ? 1231 : 1237);
-        result = prime * result + ((owner == null) ? 0 : owner.hashCode());
-        result = prime * result + ((slot == null) ? 0 : slot.hashCode());
+        result = prime * result + owner.hashCode();
+        result = prime * result + slot.hashCode();
         return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!super.equals(obj)) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        HotSpotMonitorValue other = (HotSpotMonitorValue) obj;
-        if (eliminated != other.eliminated) {
-            return false;
+        if (obj instanceof HotSpotMonitorValue) {
+            HotSpotMonitorValue other = (HotSpotMonitorValue) obj;
+            return super.equals(obj) && eliminated == other.eliminated && owner.equals(other.owner) && slot.equals(other.slot);
         }
-        if (owner == null) {
-            if (other.owner != null) {
-                return false;
-            }
-        } else if (!owner.equals(other.owner)) {
-            return false;
-        }
-        if (slot == null) {
-            if (other.slot != null) {
-                return false;
-            }
-        } else if (!slot.equals(other.slot)) {
-            return false;
-        }
-        return true;
+        return false;
     }
 }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java	Fri May 10 23:27:19 2013 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java	Fri May 10 21:03:53 2013 +0200
@@ -61,31 +61,15 @@
 
     @Override
     public int hashCode() {
-        final int prime = 31;
-        int result = super.hashCode();
-        result = prime * result + ((valueClass == null) ? 0 : valueClass.hashCode());
-        return result;
+        return 53 * super.hashCode() + valueClass.hashCode();
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!super.equals(obj)) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
+        if (obj instanceof CompositeValue) {
+            CompositeValue other = (CompositeValue) obj;
+            return super.equals(other) && valueClass.equals(other.valueClass);
         }
-        CompositeValue other = (CompositeValue) obj;
-        if (valueClass == null) {
-            if (other.valueClass != null) {
-                return false;
-            }
-        } else if (!valueClass.equals(other.valueClass)) {
-            return false;
-        }
-        return true;
+        return false;
     }
 }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/Variable.java	Fri May 10 23:27:19 2013 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/Variable.java	Fri May 10 21:03:53 2013 +0200
@@ -57,24 +57,15 @@
 
     @Override
     public int hashCode() {
-        return 31 * super.hashCode() + index;
+        return 71 * super.hashCode() + index;
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!super.equals(obj)) {
-            return false;
+        if (obj instanceof Variable) {
+            Variable other = (Variable) obj;
+            return super.equals(other) && index == other.index;
         }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        Variable other = (Variable) obj;
-        if (index != other.index) {
-            return false;
-        }
-        return true;
+        return false;
     }
 }