From 8ea34ab176f56ffae16a390c3495fb4679ed779a Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Sat, 27 May 2023 22:51:00 +0800 Subject: [PATCH] dns_conf: A little bit of performance optimization --- src/lib/conf.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/conf.c b/src/lib/conf.c index 3980143..73979b6 100644 --- a/src/lib/conf.c +++ b/src/lib/conf.c @@ -347,6 +347,7 @@ static int load_conf_file(const char *file, struct config_item *items, conf_erro char value[MAX_LINE_LEN]; int filed_num = 0; int i = 0; + int last_item_index = -1; int argc = 0; char *argv[1024]; int ret = 0; @@ -392,13 +393,21 @@ static int load_conf_file(const char *file, struct config_item *items, conf_erro goto errout; } - for (i = 0;; i++) { + for (i = last_item_index;; i++) { + if (i < 0) { + continue; + } + if (items[i].item == NULL) { handler(file, line_no, CONF_RET_NOENT); break; } if (strncmp(items[i].item, key, MAX_KEY_LEN) != 0) { + if (last_item_index >= 0) { + i = -1; + last_item_index = -1; + } continue; } @@ -422,6 +431,7 @@ static int load_conf_file(const char *file, struct config_item *items, conf_erro current_conf_file = last_file; } + last_item_index = i; break; } }