From: Douglas Bagnall Date: Fri, 26 Jul 2024 03:47:03 +0000 (+1200) Subject: ldb:ldb_pack: filter avoids looping over msg when attrs contain "*" X-Git-Tag: tdb-1.4.13~265 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=77ad9096d0c7a7e5f8257e5fe4ea0bcb12636c43;p=thirdparty%2Fsamba.git ldb:ldb_pack: filter avoids looping over msg when attrs contain "*" Signed-off-by: Douglas Bagnall Reviewed-by: Andreas Schneider --- diff --git a/lib/ldb/common/ldb_pack.c b/lib/ldb/common/ldb_pack.c index 4c2052372be..409be590611 100644 --- a/lib/ldb/common/ldb_pack.c +++ b/lib/ldb/common/ldb_pack.c @@ -1294,19 +1294,23 @@ int ldb_filter_attrs_in_place(struct ldb_message *msg, keep_all = true; } + if (keep_all) { + return LDB_SUCCESS; + } + /* + * Find the intersection between the msg elements and attrs. + * + * TODO, maybe: use a faster algorithm when (n * m) is too large. + */ for (i = 0; i < msg->num_elements; i++) { bool found = false; unsigned int j; - if (keep_all) { - found = true; - } else { - for (j = 0; attrs[j]; j++) { - int cmp = ldb_attr_cmp(msg->elements[i].name, attrs[j]); - if (cmp == 0) { - found = true; - break; - } + for (j = 0; attrs[j]; j++) { + int cmp = ldb_attr_cmp(msg->elements[i].name, attrs[j]); + if (cmp == 0) { + found = true; + break; } }