Skip to content

Commit

Permalink
Removed redundant checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim2266 committed Oct 20, 2015
1 parent e1e58dc commit b9a9f7c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
44 changes: 16 additions & 28 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b9a9f7c

Please sign in to comment.