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

Joshua Colp asteriskteam at digium.com
Fri Apr 2 12:58:09 CDT 2021


Joshua Colp has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15741 )

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:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  Kevin Harwell: Looks good to me, approved
  George Joseph: Looks good to me, but someone else must approve



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/+/15741
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ia0336a7185f9180ccba4b6f631a00f9a22a36e92
Gerrit-Change-Number: 15741
Gerrit-PatchSet: 2
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/2d7e9e70/attachment.html>


More information about the asterisk-code-review mailing list