[Asterisk-code-review] json.c: improve ast json to ast variables performance (asterisk[15])

Joshua Colp asteriskteam at digium.com
Thu Jul 26 08:58:00 CDT 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/9691 )

Change subject: json.c: improve ast_json_to_ast_variables performance
......................................................................

json.c: improve ast_json_to_ast_variables performance

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
---
M main/json.c
1 file changed, 2 insertions(+), 1 deletion(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  George Joseph: Looks good to me, approved



diff --git a/main/json.c b/main/json.c
index 7d7bd1d..4714519 100644
--- a/main/json.c
+++ b/main/json.c
@@ -1044,6 +1044,7 @@
 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;
 
@@ -1080,7 +1081,7 @@
 			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;

-- 
To view, visit https://gerrit.asterisk.org/9691
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: I8bf496a1fc449485150d6db36bfc0354934a3977
Gerrit-Change-Number: 9691
Gerrit-PatchSet: 1
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180726/511be34a/attachment.html>


More information about the asterisk-code-review mailing list