aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEtienne Bergeron2013-11-27 19:29:23 (EST)
committerAlexandre Montplaisir2013-11-28 14:41:54 (EST)
commit584f23a6868aae533a726052ec71b1377a973370 (patch)
treee4b032b50a323c6fea85372baecde3a648c737ea
parent94df6d293ae903700b3c26eacc7095b13a4ed6d4 (diff)
downloadorg.eclipse.linuxtools-584f23a6868aae533a726052ec71b1377a973370.zip
org.eclipse.linuxtools-584f23a6868aae533a726052ec71b1377a973370.tar.gz
org.eclipse.linuxtools-584f23a6868aae533a726052ec71b1377a973370.tar.bz2
tmf: Cleanup TmfStateValue to remove 1-level of indirection.refs/changes/27/19027/8
This is a refactoring to diminush the memory usage of the StateSystem. In the current implementation, each TmfStateValue has a "box" for an other object (i.e. Integer, Double, String, ...). We propose to remove this indirection and use the raw type inside the corresponding type. As an example, IntegerStateValue now contains an "int" instead of an "Integer". Change-Id: Iaa75172be42174ebd6dc7d9bdd434631077c0146 Signed-off-by: Etienne Bergeron <etienne.bergeron@gmail.com> Reviewed-on: https://git.eclipse.org/r/19027 Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Hudson CI Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/DoubleStateValue.java22
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/IntegerStateValue.java23
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/LongStateValue.java20
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/NullStateValue.java13
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/StringStateValue.java23
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java50
6 files changed, 74 insertions, 77 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/DoubleStateValue.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/DoubleStateValue.java
index 13578b8..dd3f98d 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/DoubleStateValue.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/DoubleStateValue.java
@@ -21,10 +21,10 @@ import org.eclipse.jdt.annotation.Nullable;
*/
final class DoubleStateValue extends TmfStateValue {
- private final Double valueDouble;
+ private final double value;
public DoubleStateValue(double value) {
- valueDouble = new Double(value);
+ this.value = value;
}
@Override
@@ -38,13 +38,23 @@ final class DoubleStateValue extends TmfStateValue {
}
@Override
- public Double getValue() {
- return valueDouble;
+ public boolean equals(@Nullable Object object) {
+ if (!(object instanceof DoubleStateValue)) {
+ return false;
+ }
+ DoubleStateValue other = (DoubleStateValue) object;
+ return (Double.compare(this.value, other.value) == 0);
+ }
+
+ @Override
+ public int hashCode() {
+ long bits = Double.doubleToLongBits(value);
+ return ((int) bits) ^ ((int) (bits >>> 32));
}
@Override
public @Nullable String toString() {
- return String.format("%3f", valueDouble); //$NON-NLS-1$
+ return String.format("%3f", value); //$NON-NLS-1$
}
// ------------------------------------------------------------------------
@@ -53,6 +63,6 @@ final class DoubleStateValue extends TmfStateValue {
@Override
public double unboxDouble() {
- return valueDouble;
+ return value;
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/IntegerStateValue.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/IntegerStateValue.java
index 9a43a63..9ac7d5e 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/IntegerStateValue.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/IntegerStateValue.java
@@ -22,10 +22,10 @@ import org.eclipse.jdt.annotation.Nullable;
*/
final class IntegerStateValue extends TmfStateValue {
- private final Integer valueInt;
+ private final int value;
public IntegerStateValue(int valueAsInt) {
- this.valueInt = new Integer(valueAsInt);
+ this.value = valueAsInt;
}
@Override
@@ -39,13 +39,22 @@ final class IntegerStateValue extends TmfStateValue {
}
@Override
- public Integer getValue() {
- return valueInt;
+ public boolean equals(@Nullable Object object) {
+ if (!(object instanceof IntegerStateValue)) {
+ return false;
+ }
+ IntegerStateValue other = (IntegerStateValue) object;
+ return (this.value == other.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return value;
}
@Override
public @Nullable String toString() {
- return String.format("%3d", valueInt); //$NON-NLS-1$
+ return String.format("%3d", value); //$NON-NLS-1$
}
// ------------------------------------------------------------------------
@@ -54,12 +63,12 @@ final class IntegerStateValue extends TmfStateValue {
@Override
public int unboxInt() {
- return valueInt;
+ return value;
}
@Override
public long unboxLong() {
/* It's always safe to up-cast a int into a long */
- return valueInt;
+ return value;
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/LongStateValue.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/LongStateValue.java
index 1e31495..6afe4ae 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/LongStateValue.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/LongStateValue.java
@@ -22,10 +22,10 @@ import org.eclipse.jdt.annotation.Nullable;
*/
final class LongStateValue extends TmfStateValue {
- private final Long valueLong;
+ private final long value;
public LongStateValue(long valueAsLong) {
- this.valueLong = new Long(valueAsLong);
+ this.value = valueAsLong;
}
@Override
@@ -37,15 +37,23 @@ final class LongStateValue extends TmfStateValue {
public boolean isNull() {
return false;
}
+ @Override
+ public boolean equals(@Nullable Object object) {
+ if (!(object instanceof LongStateValue)) {
+ return false;
+ }
+ LongStateValue other = (LongStateValue) object;
+ return (this.value == other.value);
+ }
@Override
- public Long getValue() {
- return valueLong;
+ public int hashCode() {
+ return ((int) value) ^ ((int) (value >>> 32));
}
@Override
public @Nullable String toString() {
- return String.format("%3d", valueLong); //$NON-NLS-1$
+ return String.format("%3d", value); //$NON-NLS-1$
}
// ------------------------------------------------------------------------
@@ -54,6 +62,6 @@ final class LongStateValue extends TmfStateValue {
@Override
public long unboxLong() {
- return valueLong;
+ return value;
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/NullStateValue.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/NullStateValue.java
index 747eb55..6460fb4 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/NullStateValue.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/NullStateValue.java
@@ -12,6 +12,8 @@
package org.eclipse.linuxtools.tmf.core.statevalue;
+import org.eclipse.jdt.annotation.Nullable;
+
/**
* A state value that contains no particular value. It is sometimes needed over
* a "null" reference, since we avoid NPE's this way.
@@ -36,8 +38,13 @@ final class NullStateValue extends TmfStateValue {
}
@Override
- public Object getValue() {
- return value;
+ public boolean equals(@Nullable Object object) {
+ return (object instanceof NullStateValue);
+ }
+
+ @Override
+ public int hashCode() {
+ return 0;
}
@Override
@@ -66,6 +73,6 @@ final class NullStateValue extends TmfStateValue {
@Override
public String unboxStr() {
- return "nullValue"; //$NON-NLS-1$
+ return value;
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/StringStateValue.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/StringStateValue.java
index 674abc1..0543e9b 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/StringStateValue.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/StringStateValue.java
@@ -12,6 +12,8 @@
package org.eclipse.linuxtools.tmf.core.statevalue;
+import org.eclipse.jdt.annotation.Nullable;
+
/**
* A state value containing a variable-sized string
*
@@ -20,10 +22,10 @@ package org.eclipse.linuxtools.tmf.core.statevalue;
*/
final class StringStateValue extends TmfStateValue {
- private final String valueStr;
+ private final String value;
public StringStateValue(String valueAsString) {
- this.valueStr = valueAsString;
+ this.value = valueAsString;
}
@Override
@@ -37,13 +39,22 @@ final class StringStateValue extends TmfStateValue {
}
@Override
- public String getValue() {
- return valueStr;
+ public boolean equals(@Nullable Object object) {
+ if (!(object instanceof StringStateValue)) {
+ return false;
+ }
+ StringStateValue other = (StringStateValue) object;
+ return value.equals(other.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return value.hashCode();
}
@Override
public String toString() {
- return valueStr;
+ return value;
}
// ------------------------------------------------------------------------
@@ -52,6 +63,6 @@ final class StringStateValue extends TmfStateValue {
@Override
public String unboxStr() {
- return valueStr;
+ return value;
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java
index 3ce0fd1..a2eaca6 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java
@@ -29,54 +29,6 @@ import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
* @author Alexandre Montplaisir
*/
public abstract class TmfStateValue implements ITmfStateValue {
-
- /**
- * Retrieve directly the value object contained within. Implementing
- * subclasses may limit the return type here.
- *
- * It's protected, since we do not want to expose this directly in the
- * public API (and require all its users to manually cast to the right
- * types). All accesses to the values should go through the "unbox-"
- * methods.
- *
- * @return The underneath object assigned to this state value.
- */
- protected abstract Object getValue();
-
- @Override
- public boolean equals(@Nullable Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof TmfStateValue)) {
- return false;
- }
-
- /* If both types are different they're necessarily not equal */
- if (this.getType() != ((TmfStateValue) other).getType()) {
- return false;
- }
-
- /*
- * This checks for the case where we'd compare two null values (and so
- * avoid a NPE below)
- */
- if (this.isNull()) {
- return true;
- }
-
- /* The two are valid and comparable, let's compare them */
- return this.getValue().equals(((TmfStateValue) other).getValue());
- }
-
- @Override
- public int hashCode() {
- if (this.isNull()) {
- return 0;
- }
- return this.getValue().hashCode();
- }
-
// ------------------------------------------------------------------------
// Factory methods to instantiate new state values
// ------------------------------------------------------------------------
@@ -133,7 +85,7 @@ public abstract class TmfStateValue implements ITmfStateValue {
* @return The newly-created TmfStateValue object
*/
public static TmfStateValue newValueDouble(double value) {
- if (value == Double.NaN) {
+ if (Double.isNaN(value)) {
return nullValue();
}
return new DoubleStateValue(value);