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

Joshua Colp asteriskteam at digium.com
Thu Jul 26 08:57:41 CDT 2018


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

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 1837b5b..0cfeac8 100644
--- a/main/json.c
+++ b/main/json.c
@@ -1046,6 +1046,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;
 
@@ -1082,7 +1083,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/9690
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I8bf496a1fc449485150d6db36bfc0354934a3977
Gerrit-Change-Number: 9690
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/6607b898/attachment.html>


More information about the asterisk-code-review mailing list