1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-17 01:12:23 +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); PackRead *const allowList = pckReadNewC(optionalRules.allowList, optionalRules.allowListSize);
bool allowListFound = false; 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) case cfgOptTypeStringId:
{ allowListFound = parseRuleValueStrId[valueIdx] == configOptionValue->value.stringId;
allowListFound = true;
break; break;
}
} default:
}
else
{ {
ASSERT(parseRuleOption[optionId].type == cfgOptTypeSize); ASSERT(parseRuleOption[optionId].type == cfgOptTypeSize);
while (pckReadNext(allowList)) allowListFound = parseRuleValueInt[valueIdx] == configOptionValue->value.integer;
{
if (parseRuleValueInt[pckReadU32P(allowList)] == configOptionValue->value.integer)
{
allowListFound = true;
break; break;
} }
} }
// Stop when value is found or allow list is exhausted
if (allowListFound || !pckReadNext(allowList))
break;
} }
pckReadFree(allowList); pckReadFree(allowList);