From da12ee9952674078efda7fa5bb98becde4c6a6ae Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Wed, 3 Jun 2015 17:16:10 +0200 Subject: [PATCH 088/257] mandocdb: Normalize inodevs to get reproducible results This is a proof-of-concept that scales poorly due to linear searches. The proper fix is probably to use hash-based lookups and only do it when the user wants reproducible results. I didn't find any automated tests for this so the only testing done is "does 'man' appear to be usable". It indeed appears to be ... Obtained from: ElectroBSD --- contrib/mdocml/mandocdb.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/contrib/mdocml/mandocdb.c b/contrib/mdocml/mandocdb.c index 3b9bda0d612b..5bdbb563c6c5 100644 --- a/contrib/mdocml/mandocdb.c +++ b/contrib/mdocml/mandocdb.c @@ -946,6 +946,34 @@ filescan(const char *file) mlink_add(mlink, &st); } +/* + * Messes up inodevs in a reproducible way as long as + * the call order does not change. The implementation + * is silly and only used as proof of concept. + */ +#define HOPEFULLY_ENOUGH_FOR_EVERYBODY 5000 +static void +normalize_inodev(struct inodev *inodev) { + static size_t table[HOPEFULLY_ENOUGH_FOR_EVERYBODY]; + size_t key; + int i; + + key = inodev->st_ino + inodev->st_dev; + + for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { + if (table[i] == 0) { + /* New value, add to table*/ + table[i] = key; + } + if (table[i] == key) { + /* Use index as new value */ + inodev->st_ino = i; + inodev->st_dev = i; + return; + } + } +} + static void mlink_add(struct mlink *mlink, const struct stat *st) { @@ -976,6 +1004,7 @@ mlink_add(struct mlink *mlink, const struct stat *st) memset(&inodev, 0, sizeof(inodev)); /* Clear padding. */ inodev.st_ino = st->st_ino; inodev.st_dev = st->st_dev; + normalize_inodev(&inodev); slot = ohash_lookup_memory(&mpages, (char *)&inodev, sizeof(struct inodev), inodev.st_ino); mpage = ohash_find(&mpages, slot); -- 2.11.0