From 0cd8829330b9ef1281c514754b816c1e71068baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20B=C3=B6ving?= Date: Sun, 29 Dec 2024 12:39:17 +0100 Subject: [PATCH] perf: some branch hints --- src/runtime/object.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/runtime/object.cpp b/src/runtime/object.cpp index f10e6c57984c..d2a4103a739c 100644 --- a/src/runtime/object.cpp +++ b/src/runtime/object.cpp @@ -2389,13 +2389,14 @@ extern "C" LEAN_EXPORT obj_res lean_copy_expand_array(obj_arg a, bool expand) { extern "C" LEAN_EXPORT object * lean_array_push(obj_arg a, obj_arg v) { object * r; - if (lean_is_exclusive(a)) { - if (lean_array_capacity(a) > lean_array_size(a)) + bool capacity_enough = lean_array_capacity(a) > lean_array_size(a); + if (LEAN_LIKELY(lean_is_exclusive(a))) { + if (LEAN_LIKELY(capacity_enough)) r = a; else r = lean_copy_expand_array(a, true); } else { - r = lean_copy_expand_array(a, lean_array_capacity(a) < lean_array_size(a) + 1); + r = lean_copy_expand_array(a, !capacity_enough); } lean_assert(lean_array_capacity(r) > lean_array_size(r)); size_t & sz = lean_to_array(r)->m_size;