philadelphia-core: Optimize 'FIXValue#setFloat'
Optimize handling of positive numbers at the expense of negative
numbers. This decreases the bytecode size of the method from 169
to 161 bytes.
@@ -399,11 +399,42 @@ public class FIXValue {
* @see #asFloat
*/
public void setFloat(double x, int decimals) {
+ if (x < 0.0) {
+ setNegativeFloat(x, decimals);
+ return;
+ }
+
+ int i = end;
+
+ bytes[--i] = SOH;
+
+ long y = Math.round(POWERS_OF_TEN[decimals] * x);
+
+ for (int j = 0; j < decimals; j++) {
+ bytes[--i] = (byte)('0' + y % 10);
+
+ y /= 10;
+ }
+
+ if (decimals > 0)
+ bytes[--i] = '.';
+
+ do {
+ bytes[--i] = (byte)('0' + y % 10);
+
+ y /= 10;
+ } while (y > 0);
+
+ offset = i;
+ length = end - offset - 1;
+ }
+
+ private void setNegativeFloat(double x, int decimals) {
int i = end;
bytes[--i] = SOH;
- long y = Math.round(POWERS_OF_TEN[decimals] * Math.abs(x));
+ long y = Math.round(POWERS_OF_TEN[decimals] * -x);
for (int j = 0; j < decimals; j++) {
bytes[--i] = (byte)('0' + y % 10);
@@ -420,7 +451,6 @@ public class FIXValue {
y /= 10;
} while (y > 0);
- if (x < 0)
bytes[--i] = '-';
offset = i;
