1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

Refactor allow list processing in config/parse module.

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).
This commit is contained in:
David Steele 2023-05-24 09:56:32 +03:00
parent 48b26bf569
commit de46276bf6

View File

@ -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)
{
while (pckReadNext(allowList))
{
if (parseRuleValueStrId[pckReadU32P(allowList)] == configOptionValue->value.stringId)
{
allowListFound = true;
break;
}
}
}
else
{
ASSERT(parseRuleOption[optionId].type == cfgOptTypeSize);
pckReadNext(allowList);
while (pckReadNext(allowList))
while (true)
{
// Compare based on option type
const unsigned int valueIdx = pckReadU32P(allowList);
switch (parseRuleOption[optionId].type)
{
if (parseRuleValueInt[pckReadU32P(allowList)] == configOptionValue->value.integer)
case cfgOptTypeStringId:
allowListFound = parseRuleValueStrId[valueIdx] == configOptionValue->value.stringId;
break;
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);