From: Andreas Gruenbacher Date: Sun, 26 Jan 2025 10:22:33 +0000 (+0100) Subject: bcachefs: eytzinger0_find_test improvement X-Git-Tag: v6.15-rc1~146^2~121 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e8a0966ffaa6aae8d64a0159a47541e32f2f587a;p=thirdparty%2Fkernel%2Flinux.git bcachefs: eytzinger0_find_test improvement In eytzinger0_find_test(), remember the smallest element seen so far instead of comparing adjacent array elements. Signed-off-by: Andreas Gruenbacher Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/util.c b/fs/bcachefs/util.c index 2af77c410179c..4114e5264965b 100644 --- a/fs/bcachefs/util.c +++ b/fs/bcachefs/util.c @@ -808,15 +808,18 @@ void eytzinger0_find_test(void) u16 *test_array = kmalloc_array(allocated, sizeof(test_array[0]), GFP_KERNEL); for (nr = 1; nr < allocated; nr++) { + u16 prev = 0; + pr_info("testing %u elems\n", nr); get_random_bytes(test_array, nr * sizeof(test_array[0])); eytzinger0_sort(test_array, nr, sizeof(test_array[0]), cmp_u16, NULL); /* verify array is sorted correctly: */ - eytzinger0_for_each(j, nr) - BUG_ON(j != eytzinger0_last(nr) && - test_array[j] > test_array[eytzinger0_next(j, nr)]); + eytzinger0_for_each(j, nr) { + BUG_ON(test_array[j] < prev); + prev = test_array[j]; + } for (i = 0; i < U16_MAX; i += 1 << 12) eytzinger0_find_test_val(test_array, nr, i);