[Asterisk-code-review] loader.c: Speed up deprecation metadata lookup (asterisk[16])

Friendly Automation asteriskteam at digium.com
Fri Apr 2 12:56:16 CDT 2021


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15725 )

Change subject: loader.c: Speed up deprecation metadata lookup
......................................................................

loader.c: Speed up deprecation metadata lookup

Only use an XPath query once per module, then just navigate the DOM for
everything else.

Change-Id: Ia0336a7185f9180ccba4b6f631a00f9a22a36e92
---
M main/loader.c
1 file changed, 28 insertions(+), 23 deletions(-)

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



diff --git a/main/loader.c b/main/loader.c
index f06016c..aafcd3b 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -2422,33 +2422,38 @@
 			continue;
 		}
 
-		results = ast_xmldoc_query("/docs/module[@name='%s']/deprecated_in", mod_name);
-		deprecated_in[0] = '\0';
-		if (results) {
-			const char *result_tmp = ast_xml_get_text(ast_xml_xpath_get_first_result(results));
-			if (!ast_strlen_zero(result_tmp)) {
-				ast_copy_string(deprecated_in, result_tmp, sizeof(deprecated_in));
-			}
-			ast_xml_xpath_results_free(results);
-		}
+		/* Clear out the previous values */
+		deprecated_in[0] = removed_in[0] = replacement[0] = 0;
 
-		results = ast_xmldoc_query("/docs/module[@name='%s']/removed_in", mod_name);
-		removed_in[0] = '\0';
+		results = ast_xmldoc_query("/docs/module[@name='%s']", mod_name);
 		if (results) {
-			const char *result_tmp = ast_xml_get_text(ast_xml_xpath_get_first_result(results));
-			if (!ast_strlen_zero(result_tmp)) {
-				ast_copy_string(removed_in, result_tmp, sizeof(removed_in));
-			}
-			ast_xml_xpath_results_free(results);
-		}
+			struct ast_xml_node *deprecated_node, *removed_node, *replacement_node;
+			struct ast_xml_node *metadata_nodes = ast_xml_node_get_children(ast_xml_xpath_get_first_result(results));
 
-		results = ast_xmldoc_query("/docs/module[@name='%s']/replacement", mod_name);
-		replacement[0] = '\0';
-		if (results) {
-			const char *result_tmp = ast_xml_get_text(ast_xml_xpath_get_first_result(results));
-			if (!ast_strlen_zero(result_tmp)) {
-				ast_copy_string(replacement, result_tmp, sizeof(replacement));
+			deprecated_node = ast_xml_find_element(metadata_nodes, "deprecated_in", NULL, NULL);
+			if (deprecated_node) {
+				const char *result_tmp = ast_xml_get_text(deprecated_node);
+				if (!ast_strlen_zero(result_tmp)) {
+					ast_copy_string(deprecated_in, result_tmp, sizeof(deprecated_in));
+				}
 			}
+
+			removed_node = ast_xml_find_element(metadata_nodes, "removed_in", NULL, NULL);
+			if (removed_node) {
+				const char *result_tmp = ast_xml_get_text(removed_node);
+				if (!ast_strlen_zero(result_tmp)) {
+					ast_copy_string(removed_in, result_tmp, sizeof(removed_in));
+				}
+			}
+
+			replacement_node = ast_xml_find_element(metadata_nodes, "replacement", NULL, NULL);
+			if (replacement_node) {
+				const char *result_tmp = ast_xml_get_text(replacement_node);
+				if (!ast_strlen_zero(result_tmp)) {
+					ast_copy_string(replacement, result_tmp, sizeof(replacement));
+				}
+			}
+
 			ast_xml_xpath_results_free(results);
 		}
 

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ia0336a7185f9180ccba4b6f631a00f9a22a36e92
Gerrit-Change-Number: 15725
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210402/ab309b8b/attachment.html>


More information about the asterisk-code-review mailing list