From b9a9f7c2d05aad8a8286a01d134a44603521cf0d Mon Sep 17 00:00:00 2001 From: Maxim Date: Tue, 20 Oct 2015 13:54:40 +0100 Subject: [PATCH] Removed redundant checks. --- README.md | 8 ++++---- src/parser.c | 44 ++++++++++++++++---------------------------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 1886a3b..c188891 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ _OS:_ Linux Mint 17.2 64bit FIX message type | FIX specification | Validation | Average time to parse one message ----------------------------------|------------------------------------------|------------|---------------------------------- NewOrderSingle('D') | Hand-coded spec. for this message only | No | 0.326 µs/msg -NewOrderSingle('D') | Hand-coded spec. for this message only | Yes | 0.562 µs/msg -NewOrderSingle('D') | Compiled full spec. for FIX.4.4 | Yes | 0.722 µs/msg -MarketDataIncrementalRefresh('X') | Hand-coded spec. for this message only | Yes | 1.071 µs/msg -MarketDataIncrementalRefresh('X') | Compiled full spec. for FIX.4.4 | Yes | 1.285 µs/msg +NewOrderSingle('D') | Hand-coded spec. for this message only | Yes | 0.563 µs/msg +NewOrderSingle('D') | Compiled full spec. for FIX.4.4 | Yes | 0.735 µs/msg +MarketDataIncrementalRefresh('X') | Hand-coded spec. for this message only | Yes | 1.061 µs/msg +MarketDataIncrementalRefresh('X') | Compiled full spec. for FIX.4.4 | Yes | 1.265 µs/msg For more details see `doc/` directory of the project. diff --git a/src/parser.c b/src/parser.c index cebe445..849308f 100644 --- a/src/parser.c +++ b/src/parser.c @@ -161,21 +161,14 @@ unsigned next_tag(fix_parser* const parser) // read tag const unsigned tag = parser->result.error.tag = read_uint(parser, '='); - if(tag == 0) // invalid tag + if(tag != 0) { - parser->result.error.code = FE_INVALID_TAG; - return 0; - } - - if(parser->frame.begin == parser->frame.end) // empty tag value - { - parser->result.error.code = FE_EMPTY_VALUE; - return 0; + parser->result.error.code = FE_OK; + return tag; } - // all done - parser->result.error.code = FE_OK; - return tag; + parser->result.error.code = FE_INVALID_TAG; + return 0; } // match the next tag @@ -205,8 +198,14 @@ unsigned read_uint_value(fix_parser* const parser) { const unsigned val = read_uint(parser, SOH); - parser->result.error.code = (val != 0) ? FE_OK : FE_INCORRECT_VALUE_FORMAT; - return val; + if(val != 0) + { + parser->result.error.code = FE_OK; + return val; + } + + parser->result.error.code = FE_INCORRECT_VALUE_FORMAT; + return 0; } static @@ -334,16 +333,11 @@ void read_binary_and_get_next(fix_parser* const parser, const unsigned bin_tag, // read length value const unsigned len = read_uint_value(parser); - fix_error_details* const details = &parser->result.error; - if(details->code != FE_OK) + if(len == 0) return; // something has gone wrong - if(len == 0) // nothing to do, just proceed to the next tag - { - next_tag(parser); - return; - } + fix_error_details* const details = &parser->result.error; // save length tag and context for error reporting const unsigned len_tag = details->tag; @@ -416,15 +410,9 @@ void read_group_and_get_next(fix_parser* const parser, const fix_group_info* con // read number of nodes const unsigned len = read_uint_value(parser); - if(parser->result.error.code != FE_OK) + if(len == 0) return; // something has gone wrong - if(len == 0) // nothing to do, just proceed to the next tag - { - next_tag(parser); - return; - } - if(len > MAX_GROUP_SIZE) { parser->result.error.code = FE_INVALID_VALUE;