From: Uwe Hermann Date: Fri, 18 May 2018 18:14:19 +0000 (+0200) Subject: srd_inst_find_by_obj(): Minor performance improvement. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=996b17db506ceb435ae3ed53d4c6ac66e10c7b34;p=libsigrokdecode.git 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. --- 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;