philadelphia-core: Optimize 'FIXValue#setInt'
Optimize handling of positive numbers at the expense of negative
numbers. This decreases the bytecode size of the method from 94
to 79 bytes.
@@ -283,19 +283,36 @@ public class FIXValue {
* @param x an integer
*/
public void setInt(long x) {
+ if (x < 0) {
+ setNegativeInt(x);
+ return;
+ }
+
int i = end;
bytes[--i] = SOH;
- long y = Math.abs(x);
+ do {
+ bytes[--i] = (byte)('0' + x % 10);
+
+ x /= 10;
+ } while (x > 0);
+
+ offset = i;
+ length = end - offset - 1;
+ }
+
+ private void setNegativeInt(long x) {
+ int i = end;
+
+ bytes[--i] = SOH;
do {
- bytes[--i] = (byte)('0' + y % 10);
+ bytes[--i] = (byte)('0' - x % 10);
- y /= 10;
- } while (y > 0);
+ x /= 10;
+ } while (x < 0);
- if (x < 0)
bytes[--i] = '-';
offset = i;
