philadelphia-core: Extract 'FIXMessageParser#acceptCheckSum' method
Having the incoming CheckSum(10) check in a separate method makes
message parsing 9.6% faster in the performance test when the incoming
CheckSum(10) check is disabled and 3.7% faster when it is enabled.
@@ -124,30 +124,9 @@ public class FIXMessageParser {
position = buffer.position();
- if (checkSumEnabled) {
- buffer.position(position + length);
-
- // Garbled message
- tag = FIXTags.get(buffer);
- if (tag == 0)
- continue;
-
- // Garbled message
- if (!checkSum.get(buffer))
+ if (checkSumEnabled && !acceptCheckSum(buffer, beginning, position, length))
continue;
- // Garbled message
- if (tag != CheckSum)
- continue;
-
- // Garbled message
- if ((FIXCheckSums.sum(buffer, beginning, position - beginning + length) & 0xff)
- != checkSum.asInt())
- continue;
-
- buffer.position(position);
- }
-
int limit = buffer.limit();
buffer.limit(position + length);
@@ -167,4 +146,30 @@ public class FIXMessageParser {
}
}
+ private boolean acceptCheckSum(ByteBuffer buffer, int beginning, int position, int length) throws IOException {
+ buffer.position(position + length);
+
+ // Garbled message
+ int tag = FIXTags.get(buffer);
+ if (tag == 0)
+ return false;
+
+ // Garbled message
+ if (!checkSum.get(buffer))
+ return false;
+
+ // Garbled message
+ if (tag != CheckSum)
+ return false;
+
+ // Garbled message
+ if ((FIXCheckSums.sum(buffer, beginning, position - beginning + length) & 0xff)
+ != checkSum.asInt())
+ return false;
+
+ buffer.position(position);
+
+ return true;
+ }
+
}
