Skip to content

Commit

Permalink
10x faster settings parser (closed #41)
Browse files Browse the repository at this point in the history
No calls to awk per settings line
  • Loading branch information
ChillerDragon committed Aug 12, 2021
1 parent 9004824 commit 7a2904c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
16 changes: 2 additions & 14 deletions lib/include/settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,11 @@ function load_settings() {
local cfg_lower
local default_value
local validation
while read -r line
while IFS=, read -r cfg_upper cfg_lower default_value validation
do
if [[ "$line" =~ [[:space:]]*# ]]
then
continue
fi
if [[ "$(echo "$line" | xargs)" == "" ]]
then
continue
fi
cfg_upper="$(echo "$line" | awk -F',' '{ print $1 }')"
cfg_upper="${cfg_upper:1:-1}"
cfg_lower="$(echo "$line" | awk -F',' '{ print $2 }')"
cfg_lower="${cfg_lower:2:-1}"
default_value="$(echo "$line" | awk -F',' '{ print $3 }')"
default_value="${default_value:2:-1}"
validation="$(echo "$line" | awk -F',' '{ print $4 }')"
validation="${validation:2:-1}"
if [ "$init" == "1" ]
then
Expand All @@ -57,7 +45,7 @@ function load_settings() {
fi
fi
settings_index="$((settings_index+1))"
done < "$settings_file"
done < <(grep -v '^[[:space:]]*#' "$settings_file" | grep '[^",]')
}

function create_settings() {
Expand Down
2 changes: 1 addition & 1 deletion lib/include/settings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"CFG_COMPILED_BIN", "compiled_teeworlds_name", "teeworlds_srv", ""
"CFG_COMPILED_BIN_BOT", "compiled_bot_name", "chillerbot-z7", ""
"CFG_CMAKE_FLAGS", "cmake_flags", "-DCMAKE_BUILD_TYPE=Debug", ""
# 0=off 1=no duplicates 2=duplicat
# 0=off 1=no duplicates 2=duplicates
"CFG_ERROR_LOGS", "error_logs", "1", "(0|1|2)"
# "curl -d \"{\\\"err\\\":\\\"\$err\\\"}\" -H 'Content-Type: application/json' http://localhost:80/api"
"CFG_ERROR_LOGS_API", "error_logs_api", "test", ""
Expand Down

0 comments on commit 7a2904c

Please sign in to comment.