LATER ldb: Use ldb_dn_compare_base_one in ldb_match_scope
authorMatthieu Patou <mat@matws.net>
Fri, 14 Dec 2012 06:37:30 +0000 (22:37 -0800)
committerStefan Metzmacher <metze@samba.org>
Tue, 29 Jan 2013 21:03:14 +0000 (22:03 +0100)
In order to return the number of element in a DN, it has to be exploded
if it's not already the case which is costly, in most case where this
function is called DN are still in non exploded form
Also the ldb_compare_base_one has quick test for DN that are linearized but
are not case folded.

lib/ldb/common/ldb_match.c

index 5eee02dea31197a7e146a666a9af28dd6c30f43a..c6959b98f3b13f6697640998c5c80f888583773c 100644 (file)
@@ -56,10 +56,21 @@ static int ldb_match_scope(struct ldb_context *ldb,
                break;
 
        case LDB_SCOPE_ONELEVEL:
-               if (ldb_dn_get_comp_num(dn) == (ldb_dn_get_comp_num(base) + 1)) {
-                       if (ldb_dn_compare_base(base, dn) == 0) {
-                               ret = 1;
-                       }
+               /*
+                * We used to check the number of components
+                * so that we don't call ldb_dn_compare_base if
+                * dn->comp_num != base->comp_num + 1
+                * But ldb_dn_get_comp_num(dn) will first explode the DN
+                * if it's not already exploded. Exploding is expensive.
+                * This function is mainly used in indexes where DNs are not
+                * exploded yet (it's just linearized strings).
+                * ldb_dn_compare_base/ldb_dn_compare_base_one have a fast track
+                * for comparing just linearized strings, so let's take
+                * advantage of this.
+                */
+               if (ldb_dn_compare_base_one(base, dn) == 0)
+               {
+                       ret = 1;
                }
                break;