From 897bffa8166f643eb9063a848bb0c02455663317 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 4 Aug 2019 12:18:19 +0200 Subject: [PATCH] tdb: Speed up tdb_oob() 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 Reviewed-by: Jeremy Allison --- lib/tdb/common/io.c | 13 ++++++++++++- lib/tdb/common/transaction.c | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/tdb/common/io.c b/lib/tdb/common/io.c index f3ea7bf9856..28e808143a2 100644 --- a/lib/tdb/common/io.c +++ b/lib/tdb/common/io.c @@ -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; } diff --git a/lib/tdb/common/transaction.c b/lib/tdb/common/transaction.c index b22624820d7..4f8d1f8cdcc 100644 --- a/lib/tdb/common/transaction.c +++ b/lib/tdb/common/transaction.c @@ -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; }