cmark

My personal build of CMark ✏️

Commit
627326bed4e58cf457e8c8f2c45b2e6d7c316a54
Parent
485ef21b95e257e9d9cbcaa804c3c164f1f49a80
Author
Nick Wellnhofer <wellnhofer@aevum.de>
Date

Feature test for __builtin_expect

Diffstat

3 files changed, 16 insertions, 4 deletions

Status File Name N° Changes Insertions Deletions
Modified src/CMakeLists.txt 9 7 2
Modified src/config.h.in 1 1 0
Modified src/html/houdini.h 10 8 2
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
@@ -93,8 +93,13 @@ install(FILES cmark.h ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h
   DESTINATION include
   )
 
-include (CheckIncludeFile)
-CHECK_INCLUDE_FILE (stdbool.h HAVE_STDBOOL_H)
+# Feature tests
+include(CheckIncludeFile)
+include(CheckCSourceCompiles)
+CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
+CHECK_C_SOURCE_COMPILES(
+  "int main() { __builtin_expect(0,0); return 0; }"
+  HAVE___BUILTIN_EXPECT)
 
 CONFIGURE_FILE(
   ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
diff --git a/src/config.h.in b/src/config.h.in
@@ -6,3 +6,4 @@
   typedef char bool;
 #endif
 
+#cmakedefine HAVE___BUILTIN_EXPECT
diff --git a/src/html/houdini.h b/src/html/houdini.h
@@ -6,10 +6,16 @@ extern "C" {
 #endif
 
 #include <stdint.h>
+#include "config.h"
 #include "buffer.h"
 
-#define likely(x)       __builtin_expect((x),1)
-#define unlikely(x)     __builtin_expect((x),0)
+#ifdef HAVE___BUILTIN_EXPECT
+#	define likely(x)	__builtin_expect((x),1)
+#	define unlikely(x)	__builtin_expect((x),0)
+#else
+#	define likely(x)	(x)
+#	define unlikely(x)	(x)
+#endif
 
 #ifdef HOUDINI_USE_LOCALE
 #	define _isxdigit(c) isxdigit(c)