Add a comment describing the sorted subkeys
authorVolker Lendecke <vl@samba.org>
Sun, 22 Feb 2009 00:11:51 +0000 (01:11 +0100)
committerMichael Adam <obnox@samba.org>
Thu, 26 Feb 2009 10:05:22 +0000 (11:05 +0100)
Signed-off-by: Michael Adam <obnox@samba.org>
source3/registry/reg_backend_db.c

index f6471d04eec88936b6d3a6c8a00416b3930ea09a..344bc4124d360797db07d06e4323c3e03fb0811e 100644 (file)
@@ -881,6 +881,29 @@ done:
        return ret;
 }
 
+/*
+ * regdb_key_exists() is a very frequent operation. It can be quite
+ * time-consuming to fully fetch the parent's subkey list, talloc_strdup all
+ * subkeys and then compare the keyname linearly to all the parent's subkeys.
+ *
+ * The following code tries to make this operation as efficient as possible:
+ * Per registry key we create a list of subkeys that is very efficient to
+ * search for existence of a subkey. Its format is:
+ *
+ * 4 bytes num_subkeys
+ * 4*num_subkey bytes offset into the string array
+ * then follows a sorted list of subkeys in uppercase
+ *
+ * This record is created by create_sorted_subkeys() on demand if it does not
+ * exist. scan_parent_subkeys() uses regdb->parse_record to search the sorted
+ * list, the parsing code and the binary search can be found in
+ * parent_subkey_scanner. The code uses parse_record() to avoid a memcpy of
+ * the potentially large subkey record.
+ *
+ * The sorted subkey record is deleted in regdb_store_keys_internal and
+ * recreated on demand.
+ */
+
 static int cmp_keynames(const void *p1, const void *p2)
 {
        return StrCaseCmp(*((char **)p1), *((char **)p2));