From b6bf7e7b0b8bd11d2c804125140b2a8077c11d85 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 21 Aug 2017 15:51:19 +1200 Subject: [PATCH] ldb_tdb: Use a binary search to speed up ltdb_dn_list_find_val() This only works if we have the GUID index format, as otherwise these are unsorted. Signed-off-by: Andrew Bartlett Reviewed-by: Garming Sam --- lib/ldb/ldb_tdb/ldb_index.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c index 97ff823ec39..d8a6958e3ce 100644 --- a/lib/ldb/ldb_tdb/ldb_index.c +++ b/lib/ldb/ldb_tdb/ldb_index.c @@ -119,12 +119,30 @@ static int ltdb_dn_list_find_val(struct ltdb_private *ltdb, const struct ldb_val *v) { unsigned int i; - for (i=0; icount; i++) { - if (ldb_val_equal_exact(&list->dn[i], v) == 1) { - return i; + struct ldb_val *exact = NULL, *next = NULL; + + if (ltdb->cache->GUID_index_attribute == NULL) { + for (i=0; icount; i++) { + if (ldb_val_equal_exact(&list->dn[i], v) == 1) { + return i; + } } + return -1; } - return -1; + + BINARY_ARRAY_SEARCH_GTE(list->dn, list->count, + *v, ldb_val_equal_exact_ordered, + exact, next); + if (exact == NULL) { + return -1; + } + /* Not required, but keeps the compiler quiet */ + if (next != NULL) { + return -1; + } + + i = exact - list->dn; + return i; } /*