From 129298c9b9793794125558b8334fd5b578ca1112 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 Oct 2009 11:16:00 +1100 Subject: s4-ldb: over-allocate index records to save on realloc costs --- source4/lib/ldb/ldb_tdb/ldb_index.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4') diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index 501907578d..606c24491c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -1065,6 +1065,7 @@ static int ltdb_index_add1(struct ldb_module *module, const char *dn, int ret; const struct ldb_schema_attribute *a; struct dn_list *list; + unsigned alloc_len; ldb = ldb_module_get_ctx(module); @@ -1096,7 +1097,10 @@ static int ltdb_index_add1(struct ldb_module *module, const char *dn, return LDB_ERR_ENTRY_ALREADY_EXISTS; } - list->dn = talloc_realloc(list, list->dn, struct ldb_val, list->count+1); + /* overallocate the list a bit, to reduce the number of + * realloc trigered copies */ + alloc_len = ((list->count+1)+7) & ~7; + list->dn = talloc_realloc(list, list->dn, struct ldb_val, alloc_len); if (list->dn == NULL) { talloc_free(list); return LDB_ERR_OPERATIONS_ERROR; -- cgit