tdb: Speed up tdb_oob()
[samba.git] / lib / tdb / common / io.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;
 }