]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
json.c: improve ast_json_to_ast_variables performance
authorKevin Harwell <kharwell@digium.com>
Wed, 25 Jul 2018 20:33:22 +0000 (15:33 -0500)
committerKevin Harwell <kharwell@digium.com>
Wed, 25 Jul 2018 20:33:22 +0000 (15:33 -0500)
When converting from a json object to an ast variables list the conversion
algorithm was doing a complete traversal of the entire variables list for
every item appended from the json structure.

This patch makes it so the list is no longer traversed for each new ast
variable being appended.

Change-Id: I8bf496a1fc449485150d6db36bfc0354934a3977

main/json.c

index 1837b5bc5ded1b965c3c116a017208b32a9ff2ce..0cfeac89c9b403c0558d552b0cf13314d6a5ad19 100644 (file)
@@ -1046,6 +1046,7 @@ struct ast_json *ast_json_party_id(struct ast_party_id *party)
 enum ast_json_to_ast_vars_code ast_json_to_ast_variables(struct ast_json *json_variables, struct ast_variable **variables)
 {
        struct ast_json_iter *it_json_var;
+       struct ast_variable *tail = NULL;
 
        *variables = NULL;
 
@@ -1082,7 +1083,7 @@ enum ast_json_to_ast_vars_code ast_json_to_ast_variables(struct ast_json *json_v
                        return AST_JSON_TO_AST_VARS_CODE_OOM;
                }
 
-               ast_variable_list_append(variables, new_var);
+               tail = ast_variable_list_append_hint(variables, tail, new_var);
        }
 
        return AST_JSON_TO_AST_VARS_CODE_SUCCESS;