sms: Optimize behavior of previous commit
authorDenis Kenzior <denkenz@gmail.com>
Wed, 12 Sep 2012 03:31:44 +0000 (22:31 -0500)
committerDenis Kenzior <denkenz@gmail.com>
Wed, 12 Sep 2012 03:33:43 +0000 (22:33 -0500)
The previous commit fixed the bug, however performing a linear-search
through the entire tx-queue is quite wasteful.  The current usage
pattern is to always modify the entry at the tail of the queue, so
optimize.

src/sms.c

index 743f725..e7e4432 100644 (file)
--- a/src/sms.c
+++ b/src/sms.c
@@ -2115,14 +2115,16 @@ int __ofono_sms_txq_set_submit_notify(struct ofono_sms *sms,
                                        ofono_destroy_func destroy)
 {
        GList *l;
-       struct tx_queue_entry *entry;
+       struct tx_queue_entry *entry = g_queue_peek_tail(sms->txq);
 
-       l = g_queue_find_custom(sms->txq, uuid, entry_compare_by_uuid);
+       if (memcmp(&entry->uuid, uuid, sizeof(entry->uuid))) {
+               l = g_queue_find_custom(sms->txq, uuid, entry_compare_by_uuid);
 
-       if (l == NULL)
-               return -ENOENT;
+               if (l == NULL)
+                       return -ENOENT;
 
-       entry = l->data;
+               entry = l->data;
+       }
 
        tx_queue_entry_set_submit_notify(entry, cb, data, destroy);