[asterisk-commits] cdr.c: Set stringfields only if they are different. (asterisk[13])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Oct 13 17:00:10 CDT 2017


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/6762 )

Change subject: cdr.c: Set stringfields only if they are different.
......................................................................

cdr.c: Set stringfields only if they are different.

The CDR performance gets worse the further it gets behind in processing
stasis messages.  One of the reasons is we were repeatedly setting string
fields to potentially the same string in base_process_party_a().  Setting
a string field involves allocating room for the new string out of a memory
pool which may have to allocate even more memory.

* Check to see if the string field is already set to the desired string.

ASTERISK-27335

Change-Id: I3ccb7e23f1488417e08cafe477755033eed65a7c
---
M main/cdr.c
1 file changed, 18 insertions(+), 8 deletions(-)

Approvals:
  Corey Farrell: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/main/cdr.c b/main/cdr.c
index c2f981c..1481ae7 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -1378,8 +1378,12 @@
 	 */
 	if (!ast_test_flag(&snapshot->flags, AST_FLAG_SUBROUTINE_EXEC)
 		|| ast_test_flag(&snapshot->softhangup_flags, AST_SOFTHANGUP_HANGUP_EXEC)) {
-		ast_string_field_set(cdr, context, snapshot->context);
-		ast_string_field_set(cdr, exten, snapshot->exten);
+		if (strcmp(cdr->context, snapshot->context)) {
+			ast_string_field_set(cdr, context, snapshot->context);
+		}
+		if (strcmp(cdr->exten, snapshot->exten)) {
+			ast_string_field_set(cdr, exten, snapshot->exten);
+		}
 	}
 
 	cdr_object_swap_snapshot(&cdr->party_a, snapshot);
@@ -1389,11 +1393,15 @@
 	 * of "AppDialX". Prevent that, and any other application changes we might not want
 	 * here.
 	 */
-	if (!ast_strlen_zero(snapshot->appl)
-			&& (strncasecmp(snapshot->appl, "appdial", 7) || ast_strlen_zero(cdr->appl))
-			&& !ast_test_flag(&cdr->flags, AST_CDR_LOCK_APP)) {
-		ast_string_field_set(cdr, appl, snapshot->appl);
-		ast_string_field_set(cdr, data, snapshot->data);
+	if (!ast_test_flag(&cdr->flags, AST_CDR_LOCK_APP)
+		&& !ast_strlen_zero(snapshot->appl)
+		&& (strncasecmp(snapshot->appl, "appdial", 7) || ast_strlen_zero(cdr->appl))) {
+		if (strcmp(cdr->appl, snapshot->appl)) {
+			ast_string_field_set(cdr, appl, snapshot->appl);
+		}
+		if (strcmp(cdr->data, snapshot->data)) {
+			ast_string_field_set(cdr, data, snapshot->data);
+		}
 
 		/* Dial (app_dial) is a special case. Because pre-dial handlers, which
 		 * execute before the dial begins, will alter the application/data to
@@ -1405,7 +1413,9 @@
 		}
 	}
 
-	ast_string_field_set(cdr, linkedid, snapshot->linkedid);
+	if (strcmp(cdr->linkedid, snapshot->linkedid)) {
+		ast_string_field_set(cdr, linkedid, snapshot->linkedid);
+	}
 	cdr_object_check_party_a_answer(cdr);
 	cdr_object_check_party_a_hangup(cdr);
 

-- 
To view, visit https://gerrit.asterisk.org/6762
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I3ccb7e23f1488417e08cafe477755033eed65a7c
Gerrit-Change-Number: 6762
Gerrit-PatchSet: 2
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-commits/attachments/20171013/701ec3c3/attachment.html>


More information about the asterisk-commits mailing list