common/messaging: use tdb_parse_record in message_list_db_fetch
authorVolker Lendecke <vl@samba.org>
Fri, 5 Apr 2013 02:11:31 +0000 (13:11 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Fri, 5 Apr 2013 04:19:59 +0000 (15:19 +1100)
This avoids malloc/free in a hot code path.
(cherry picked from commit c137531fae8f7f6392746ce1b9ac6f219775fc29)

common/ctdb_message.c

index d164837e5c10c489c886423f45042209f8f387c0..751acd3a8be035221b006183d099be147ce93979 100644 (file)
@@ -93,10 +93,24 @@ static int message_list_db_delete(struct ctdb_context *ctdb, uint64_t srvid)
        return 0;
 }
 
+static int message_list_db_fetch_parser(TDB_DATA key, TDB_DATA data,
+                                       void *private_data)
+{
+       struct ctdb_message_list_header **h =
+               (struct ctdb_message_list_header **)private_data;
+
+       if (data.dsize != sizeof(struct ctdb_message_list_header *)) {
+               return -1;
+       }
+
+       *h = *(struct ctdb_message_list_header **)data.dptr;
+       return 0;
+}
+
 static int message_list_db_fetch(struct ctdb_context *ctdb, uint64_t srvid,
                                 struct ctdb_message_list_header **h)
 {
-       TDB_DATA key, data;
+       TDB_DATA key;
 
        if (ctdb->message_list_indexdb == NULL) {
                return -1;
@@ -105,16 +119,8 @@ static int message_list_db_fetch(struct ctdb_context *ctdb, uint64_t srvid,
        key.dptr = (uint8_t *)&srvid;
        key.dsize = sizeof(uint64_t);
 
-       data = tdb_fetch(ctdb->message_list_indexdb, key);
-       if (data.dsize != sizeof(struct ctdb_message_list_header *)) {
-               talloc_free(data.dptr);
-               return -1;
-       }
-
-       *h = *(struct ctdb_message_list_header **)data.dptr;
-       talloc_free(data.dptr);
-
-       return 0;
+       return tdb_parse_record(ctdb->message_list_indexdb, key,
+                               message_list_db_fetch_parser, h);
 }
 
 /*