From 1d22da0a1c5d7cc36c8627876ef1abc5c61fec59 Mon Sep 17 00:00:00 2001 From: Tian Yuchen Date: Sun, 8 Mar 2026 22:55:23 +0800 Subject: [PATCH] patch-ids: document intentional const-casting in patch_id_neq() The hashmap API requires the comparison function to take const pointers. However, patch_id_neq() uses lazy evaluation to compute patch IDs on demand. Pre-calculating all patch IDs to achieve true const correctness would introduce an unacceptable performance penalty. Remove the eight-year-old "NEEDSWORK" comment and formally document this intentional design trade-off. Signed-off-by: Tian Yuchen --- patch-ids.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/patch-ids.c b/patch-ids.c index a5683b462c6e76..35e6a974f1b41a 100644 --- a/patch-ids.c +++ b/patch-ids.c @@ -41,7 +41,15 @@ static int patch_id_neq(const void *cmpfn_data, const struct hashmap_entry *entry_or_key, const void *keydata UNUSED) { - /* NEEDSWORK: const correctness? */ + /* + * We drop the 'const' modifier here intentionally. + * + * The hashmap API requires us to treat the entries as const. + * However, to avoid performance regression, we lazily compute + * the patch IDs inside this comparison function. This fundamentally + * requires us to mutate the 'struct patch_id'. Therefore, we use + * container_of() to cast away the constness from the hashmap_entry. + */ struct diff_options *opt = (void *)cmpfn_data; struct patch_id *a, *b;