tdb: Speed up tdb_oob()
authorVolker Lendecke <vl@samba.org>
Sun, 4 Aug 2019 10:18:19 +0000 (12:18 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 6 Aug 2019 21:49:27 +0000 (21:49 +0000)
This is common between both implementations of tdb_oob(). It's
faster if we don't have to dereference function pointers.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/tdb/common/io.c
lib/tdb/common/transaction.c

index f3ea7bf9856c7a094f57f5253ac3e65d36b1278b..28e808143a2dd966fe9d89411e6eea664207a0e3 100644 (file)
@@ -150,6 +150,11 @@ static int tdb_notrans_oob(
                return -1;
        }
 
+       /*
+        * This duplicates functionality from tdb_oob(). Don't remove:
+        * we still have direct callers of tdb->methods->tdb_oob()
+        * inside transaction.c.
+        */
        if (off + len <= tdb->map_size)
                return 0;
        if (tdb->flags & TDB_INTERNAL) {
@@ -664,7 +669,13 @@ int tdb_expand(struct tdb_context *tdb, tdb_off_t size)
 
 int tdb_oob(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len, int probe)
 {
-       int ret = tdb->methods->tdb_oob(tdb, off, len, probe);
+       int ret;
+
+       if (likely((off + len >= off) && (off + len <= tdb->map_size))) {
+               return 0;
+       }
+
+       ret = tdb->methods->tdb_oob(tdb, off, len, probe);
        return ret;
 }
 
index b22624820d7e59964f9c349254c99be1c2e87e80..4f8d1f8cdccc5d4723a4c7d7e76c8c54a31a7256 100644 (file)
@@ -378,6 +378,11 @@ static void transaction_next_hash_chain(struct tdb_context *tdb, uint32_t *chain
 static int transaction_oob(struct tdb_context *tdb, tdb_off_t off,
                           tdb_len_t len, int probe)
 {
+       /*
+        * This duplicates functionality from tdb_oob(). Don't remove:
+        * we still have direct callers of tdb->methods->tdb_oob()
+        * inside transaction.c.
+        */
        if (off + len >= off && off + len <= tdb->map_size) {
                return 0;
        }