]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-131033: Enable the optimizing macros UNLIKELY and LIKELY for Clang (GH-131019)
authorChris Eibl <138194463+chris-eibl@users.noreply.github.com>
Mon, 25 Aug 2025 20:59:52 +0000 (22:59 +0200)
committerGitHub <noreply@github.com>
Mon, 25 Aug 2025 20:59:52 +0000 (21:59 +0100)
This includes clang-cl on Windows, which does not define the GCC version that was previously being checked.

Objects/obmalloc.c

index deb7fd957e57dde8d874dd7863d68d925485f62e..2b95ebbf8e5ac06b2150ab8b3eb4c2a9e63a5c51 100644 (file)
@@ -1523,9 +1523,9 @@ PyObject_Free(void *ptr)
 }
 
 
-/* If we're using GCC, use __builtin_expect() to reduce overhead of
+/* Use __builtin_expect() where available to reduce overhead of
    the valgrind checks */
-#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
+#if (defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 2))) && defined(__OPTIMIZE__)
 #  define UNLIKELY(value) __builtin_expect((value), 0)
 #  define LIKELY(value) __builtin_expect((value), 1)
 #else