From 7a2904c3a7335dcb406af0aabf6189ce99160e12 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Thu, 12 Aug 2021 12:17:38 +0200 Subject: [PATCH] 10x faster settings parser (closed #41) No calls to awk per settings line --- lib/include/settings.sh | 16 ++-------------- lib/include/settings.txt | 2 +- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/lib/include/settings.sh b/lib/include/settings.sh index 1d2727b..b339ef5 100644 --- a/lib/include/settings.sh +++ b/lib/include/settings.sh @@ -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 @@ -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() { diff --git a/lib/include/settings.txt b/lib/include/settings.txt index b0044a9..7cb3114 100644 --- a/lib/include/settings.txt +++ b/lib/include/settings.txt @@ -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", ""