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;