ldb_tdb: Use a binary search to speed up ltdb_dn_list_find_val()
authorAndrew Bartlett <abartlet@samba.org>
Mon, 21 Aug 2017 03:51:19 +0000 (15:51 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 22 Sep 2017 19:20:23 +0000 (21:20 +0200)
This only works if we have the GUID index format, as otherwise these are unsorted.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/ldb_tdb/ldb_index.c

index 97ff823ec393499479e2f19804ece7d89b822517..d8a6958e3ced4a794d81bd847402632419039ac3 100644 (file)
@@ -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; i<list->count; 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; i<list->count; i++) {
+                       if (ldb_val_equal_exact(&list->dn[i], v) == 1) {
+                               return i;
+                       }
                }
+               return -1;
+       }
+
+       BINARY_ARRAY_SEARCH_GTE(list->dn, list->count,
+                               *v, ldb_val_equal_exact_ordered,
+                               exact, next);
+       if (exact == NULL) {
+               return -1;
        }
-       return -1;
+       /* Not required, but keeps the compiler quiet */
+       if (next != NULL) {
+               return -1;
+       }
+
+       i = exact - list->dn;
+       return i;
 }
 
 /*