perf: simpler iteration condition checking

- less complex conditions
- easier code to understand
- cleans up extraneous delimiters
- skips null entries immediately
This commit is contained in:
Asif Bacchus 2021-05-09 08:44:47 -06:00
parent 220263c1f9
commit 39f5445c28

View File

@ -369,10 +369,12 @@ else
fi fi
# iterate DNS records to update # iterate DNS records to update
dnsRecordsToUpdate="$dnsRecords$dnsSeparator" dnsRecordsToUpdate="$(printf '%s' "${1}" | sed "s/${dnsSeparator}*$//")$dnsSeparator"
while [ "$dnsRecordsToUpdate" != "${dnsRecordsToUpdate#*${dnsSeparator}}" ] && { [ -n "${dnsRecordsToUpdate%%${dnsSeparator}*}" ] || [ -n "${dnsRecordsToUpdate#*${dnsSeparator}}" ]; }; do while [ -n "$dnsRecordsToUpdate" ] && [ "$dnsRecordsToUpdate" != "$dnsSeparator" ]; do
record="${dnsRecordsToUpdate%%${dnsSeparator}*}" record="${dnsRecordsToUpdate%%${dnsSeparator}*}"
dnsRecordsToUpdate="${dnsRecordsToUpdate#*${dnsSeparator}}" dnsRecordsToUpdate="${dnsRecordsToUpdate#*${dnsSeparator}}"
if [ -z "$record" ]; then continue; fi
printf "updating record: %s\n" "$record" >>"$logFile" printf "updating record: %s\n" "$record" >>"$logFile"
done done
@ -411,9 +413,11 @@ elif [ "$ip6" -eq 1 ]; then
fi fi
# iterate hosts to update # iterate hosts to update
while [ "$dnsRecordsToUpdate" != "${dnsRecordsToUpdate#*${dnsSeparator}}" ] && { [ -n "${dnsRecordsToUpdate%%${dnsSeparator}*}" ] || [ -n "${dnsRecordsToUpdate#*${dnsSeparator}}" ]; }; do while [ -n "$dnsRecordsToUpdate" ] && [ "$dnsRecordsToUpdate" != "$dnsSeparator" ]; do
record="${dnsRecordsToUpdate%%${dnsSeparator}*}" record="${dnsRecordsToUpdate%%${dnsSeparator}*}"
dnsRecordsToUpdate="${dnsRecordsToUpdate#*${dnsSeparator}}" dnsRecordsToUpdate="${dnsRecordsToUpdate#*${dnsSeparator}}"
if [ -z "$record" ]; then continue; fi
printf "[%s] Processing %s... " "$(stamp)" "$record" >>"$logFile" printf "[%s] Processing %s... " "$(stamp)" "$record" >>"$logFile"
# exit if curl/network error # exit if curl/network error