]> sigrok.org Git - libsigrokdecode.git/commitdiff
srd_inst_find_by_obj(): Minor performance improvement.
authorUwe Hermann <redacted>
Fri, 18 May 2018 18:14:19 +0000 (20:14 +0200)
committerUwe Hermann <redacted>
Fri, 18 May 2018 18:54:36 +0000 (20:54 +0200)
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

index cff242c79999e83d3095dbb1293c0d501cc1bada..59fb0498b08d616275b5f3cc5cd03e14e1d45e83 100644 (file)
@@ -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;