浏览代码

dns_conf: A little bit of performance optimization

Nick Peng 2 年之前
父节点
当前提交
8ea34ab176
共有 1 个文件被更改,包括 11 次插入1 次删除
  1. 11 1
      src/lib/conf.c

+ 11 - 1
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];
 	char value[MAX_LINE_LEN];
 	int filed_num = 0;
 	int filed_num = 0;
 	int i = 0;
 	int i = 0;
+	int last_item_index = -1;
 	int argc = 0;
 	int argc = 0;
 	char *argv[1024];
 	char *argv[1024];
 	int ret = 0;
 	int ret = 0;
@@ -392,13 +393,21 @@ static int load_conf_file(const char *file, struct config_item *items, conf_erro
 			goto errout;
 			goto errout;
 		}
 		}
 
 
-		for (i = 0;; i++) {
+		for (i = last_item_index;; i++) {
+			if (i < 0) {
+				continue;
+			}
+
 			if (items[i].item == NULL) {
 			if (items[i].item == NULL) {
 				handler(file, line_no, CONF_RET_NOENT);
 				handler(file, line_no, CONF_RET_NOENT);
 				break;
 				break;
 			}
 			}
 
 
 			if (strncmp(items[i].item, key, MAX_KEY_LEN) != 0) {
 			if (strncmp(items[i].item, key, MAX_KEY_LEN) != 0) {
+				if (last_item_index >= 0) {
+					i = -1;
+					last_item_index = -1;
+				}
 				continue;
 				continue;
 			}
 			}
 
 
@@ -422,6 +431,7 @@ static int load_conf_file(const char *file, struct config_item *items, conf_erro
 				current_conf_file = last_file;
 				current_conf_file = last_file;
 			}
 			}
 
 
+			last_item_index = i;
 			break;
 			break;
 		}
 		}
 	}
 	}