better handling of toNumber method
GoogleCodeExporter opened this issue · 2 comments
GoogleCodeExporter commented
When returning Double the conversion is futile, and for the other cases this
works as well and does not consume so much memory.
public Number toNumber(double value) {
switch (this) {
case LONG:
return (long) value;
case DOUBLE:
return value;
case INTEGER:
return (int) value;
case FLOAT:
return new Float(value);
case SHORT:
return (short) value;
case BYTE:
return (byte) value;
case BIG_DECIMAL:
return new BigDecimal(value);
}
throw new InstantiationError("can't convert " + this + " to a Number object");
}
Original issue reported on code.google.com by pedro.ve...@emerge.pt
on 2 Apr 2012 at 10:29
GoogleCodeExporter commented
Hi Pedro, yes, the object duplication in case of a double is somewhat
unnecessary. I adapted that.
Regarding your suggestion to use primitive types + autoboxing instead of direct
object instantiation: do you have any reference that this really is more memory
efficient?
Original comment by tittel@kom.e-technik.tu-darmstadt.de
on 4 Apr 2012 at 7:01
- Added labels: Type-Enhancement
- Removed labels: Type-Defect
GoogleCodeExporter commented
Hi again. Well, actually the the autoboxing will just result in uncluttered
code, I too have doubts it is more memory or performance efficient. But in this
case this particular method wont be called millions of time in a second so the
cleaner code is preferred because the memory and performance impact of both
solutions will have the same noticeable footprint.
Also, in compile time I got the warning that this variable wasn't used anywhere
"float mTouchProgressOffset;" , it could be because I slightly altered the code
but please check if it is not used indeed.
Original comment by pedro.ve...@emerge.pt
on 7 Apr 2012 at 8:34
- Added labels: ****
- Removed labels: ****