From f2a3d2cc4b030cf350b9242967beee57eecadc5a Mon Sep 17 00:00:00 2001 From: Xiaobo Liu Date: Fri, 22 May 2026 11:35:36 +0800 Subject: [PATCH] Use mi_popcount in _mi_commit_mask_committed_size Replace the bit-by-bit loop with the existing mi_popcount() helper as noted by the inline TODO comment. This compiles to a single hardware instruction (popcnt/cnt) on modern x86_64 and ARM64. Signed-off-by: Xiaobo Liu --- src/segment.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/segment.c b/src/segment.c index 7ae84616f..75bf81f69 100644 --- a/src/segment.c +++ b/src/segment.c @@ -92,9 +92,7 @@ size_t _mi_commit_mask_committed_size(const mi_commit_mask_t* cm, size_t total) count += MI_COMMIT_MASK_FIELD_BITS; } else { - for (; mask != 0; mask >>= 1) { // todo: use popcount - if ((mask&1)!=0) count++; - } + count += mi_popcount(mask); } } // we use total since for huge segments each commit bit may represent a larger size