From d48c93af2c986f8c49ab8bb6ec35734e480816d8 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Mon, 31 May 2021 11:49:08 +0800 Subject: [PATCH] Add branch hint for _mi_os_good_alloc_size In _mi_os_good_alloc_size, overflow caused by alignment size is rare, and this patch added the appropriate branch hint during range checks. --- src/os.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os.c b/src/os.c index 2e2ec88d..5fed6b93 100644 --- a/src/os.c +++ b/src/os.c @@ -113,7 +113,7 @@ size_t _mi_os_good_alloc_size(size_t size) { else if (size < 8*MiB) align_size = 256*KiB; else if (size < 32*MiB) align_size = 1*MiB; else align_size = 4*MiB; - if (size >= (SIZE_MAX - align_size)) return size; // possible overflow? + if (mi_unlikely(size >= (SIZE_MAX - align_size))) return size; // possible overflow? return _mi_align_up(size, align_size); }