From 996b17db506ceb435ae3ed53d4c6ac66e10c7b34 Mon Sep 17 00:00:00 2001
From: Uwe Hermann <uwe@hermann-uwe.de>
Date: Fri, 18 May 2018 20:14:19 +0200
Subject: srd_inst_find_by_obj(): Minor performance improvement.

Handle the most common case of one session and one decoder first so
we can exit early. This has a small, but measurable performance benefit.
---
 type_decoder.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/type_decoder.c b/type_decoder.c
index cff242c..59fb049 100644
--- a/type_decoder.c
+++ b/type_decoder.c
@@ -256,6 +256,12 @@ static inline struct srd_decoder_inst *srd_inst_find_by_obj(
 	struct srd_session *sess;
 	GSList *l;
 
+	/* Performance shortcut: Handle the most common case first. */
+	sess = sessions->data;
+	di = sess->di_list->data;
+	if (di->py_inst == obj)
+		return di; 
+
 	di = NULL;
 	for (l = sessions; di == NULL && l != NULL; l = l->next) {
 		sess = l->data;
-- 
cgit v1.2.3-70-g09d2