From: Andrew Tridgell Date: Thu, 22 Oct 2009 00:16:00 +0000 (+1100) Subject: s4-ldb: over-allocate index records to save on realloc costs X-Git-Tag: tdb-1.2.0~523 X-Git-Url: http://git.samba.org/samba.git/?p=ira%2Fwip.git;a=commitdiff_plain;h=129298c9b9793794125558b8334fd5b578ca1112 s4-ldb: over-allocate index records to save on realloc costs --- diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index 501907578d9..606c24491cc 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;