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 02:12:58 +0000 (13:12 +1100)
This avoids malloc/free in a hot code path.

(This used to be ctdb commit c137531fae8f7f6392746ce1b9ac6f219775fc29)

ctdb/common/ctdb_message.c

index a556ac4336acc7c6d5faa7bc470594efe7b7f4cf..9700caf42e53bd93bbbd25949153a3999c88abe2 100644 (file)
@@ -92,10 +92,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;
@@ -104,16 +118,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);
 }
 
 /*