]> sigrok.org Git - libsigrokdecode.git/blobdiff - type_decoder.c
srd_inst_find_by_obj(): Minor performance improvement.
[libsigrokdecode.git] / 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;