>From 3b945a342b0051aa30e85c170967d9635fc36fc2 Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Tue, 11 Dec 2012 20:17:43 -0800 Subject: [PATCH] ldb: Check if the DN is already casefolded before calling get_casefold_internal The rational is that for construction like that: struct ldb_dn *base; struct ldb_dn **list; int list_size; int i = 0; while (i < list_size) { if (ldb_dn_compare_base(base, list[i])) { /* * Do stuff */ } } We end up doing list_size time ldb_dn_casefold_internal on the base, profiling has shown that ldb_dn_casefold_internal is very costly so there is no point calling it continiously. Signed-off-by: Matthieu Patou --- lib/ldb/common/ldb_dn.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/ldb/common/ldb_dn.c b/lib/ldb/common/ldb_dn.c index b910489..98f00f8 100644 --- a/lib/ldb/common/ldb_dn.c +++ b/lib/ldb/common/ldb_dn.c @@ -1048,12 +1048,22 @@ int ldb_dn_compare_base(struct ldb_dn *base, struct ldb_dn *dn) } } - if ( ! ldb_dn_casefold_internal(base)) { - return 1; + + /* + * Try to avoid calling casefold_internal + * if there is a casefold attribute it means that + * case_fold_internal has been already called successfully + */ + if (!base->casefold) { + if (!ldb_dn_casefold_internal(base)) { + return 1; + } } - if ( ! ldb_dn_casefold_internal(dn)) { - return -1; + if (!dn->casefold) { + if (!ldb_dn_casefold_internal(dn)) { + return -1; + } } } @@ -1130,12 +1140,21 @@ int ldb_dn_compare(struct ldb_dn *dn0, struct ldb_dn *dn1) } } - if ( ! ldb_dn_casefold_internal(dn0)) { - return 1; + /* + * Try to avoid calling casefold_internal + * if there is a casefold attribute it means that + * case_fold_internal has been already called successfully + */ + if (!dn0->casefold) { + if (!ldb_dn_casefold_internal(dn0)) { + return 1; + } } - if ( ! ldb_dn_casefold_internal(dn1)) { - return -1; + if (!dn1->casefold) { + if (!ldb_dn_casefold_internal(dn1)) { + return -1; + } } } -- 1.7.9.5