Skip to content

Commit

Permalink
Refactor allow list processing in config/parse module.
Browse files Browse the repository at this point in the history
Combine StringId and int checking into a single loop. This seems more compact and makes it easier to add code that affects both types (and possibly more types in the future).
  • Loading branch information
dwsteele committed May 24, 2023
1 parent 48b26bf commit de46276
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/config/parse.c
Expand Up @@ -2351,29 +2351,31 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha
PackRead *const allowList = pckReadNewC(optionalRules.allowList, optionalRules.allowListSize);
bool allowListFound = false;

if (parseRuleOption[optionId].type == cfgOptTypeStringId)
pckReadNext(allowList);

while (true)
{
while (pckReadNext(allowList))
// Compare based on option type
const unsigned int valueIdx = pckReadU32P(allowList);

switch (parseRuleOption[optionId].type)
{
if (parseRuleValueStrId[pckReadU32P(allowList)] == configOptionValue->value.stringId)
{
allowListFound = true;
case cfgOptTypeStringId:
allowListFound = parseRuleValueStrId[valueIdx] == configOptionValue->value.stringId;
break;
}
}
}
else
{
ASSERT(parseRuleOption[optionId].type == cfgOptTypeSize);

while (pckReadNext(allowList))
{
if (parseRuleValueInt[pckReadU32P(allowList)] == configOptionValue->value.integer)
default:
{
allowListFound = true;
ASSERT(parseRuleOption[optionId].type == cfgOptTypeSize);

allowListFound = parseRuleValueInt[valueIdx] == configOptionValue->value.integer;
break;
}
}

// Stop when value is found or allow list is exhausted
if (allowListFound || !pckReadNext(allowList))
break;
}

pckReadFree(allowList);
Expand Down

0 comments on commit de46276

Please sign in to comment.