git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/4] xdiff: annotate unlikely branch

From
Alexander Monakov <amonakov@ispras.ru>
Date
Sep 8, 2025, 18:49 UTC
Message-ID
<20250908184939.16338-2-amonakov@ispras.ru>
In-Reply-To
<20250908184939.16338-1-amonakov@ispras.ru>

XDL_ALLOC_GROW is used in a hot loop in xdl_prepare_ctx. Inform the compiler that branching to the reallocation helper happens rarely to improve code layout.

Signed-off-by: Alexander Monakov <amonakov@ispras.ru>
---
 xdiff/xmacros.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/xdiff/xmacros.h b/xdiff/xmacros.h
index 8487bb396f..d892e022d4 100644
--- a/xdiff/xmacros.h
+++ b/xdiff/xmacros.h
@@ -23,8 +23,11 @@
 #if !defined(XMACROS_H)
 #define XMACROS_H
 
-
-
+#if __GNUC__ >= 3
+#define XDL_LIKELY(e) __builtin_expect((e), 1)
+#else
+#define XDL_LIKELY(e) (e)
+#endif
 
 #define XDL_MIN(a, b) ((a) < (b) ? (a): (b))
 #define XDL_MAX(a, b) ((a) > (b) ? (a): (b))
@@ -64,8 +67,8 @@ do { \
  * elements) as necessary. Frees p and returns -1 on failure, returns
  * 0 on success
  */
-#define XDL_ALLOC_GROW(p, nr, alloc)	\
-	(-!((nr) <= (alloc) ||		\
+#define XDL_ALLOC_GROW(p, nr, alloc)	    \
+	(-!(XDL_LIKELY((nr) <= (alloc)) ||  \
 	    ((p) = xdl_alloc_grow_helper((p), (nr), &(alloc), sizeof(*(p))))))
 
 #endif /* #if !defined(XMACROS_H) */
-- 
2.49.1
Previous: Alexander Monakov
Message 4 of 4 in “xdiff: refactor xdl_hash_record()”
  1. 1/4 xdiff: refactor xdl_hash_record()Alexander Monakov, Sep 8, 2025
  2. 3/4 xdiff: move hashing functions to a separate headerAlexander Monakov, Sep 8, 2025
  3. 4/4 xdiff: use a faster hash in xdl_hash_record_verbatimAlexander Monakov, Sep 8, 2025
  4. 2/4 xdiff: annotate unlikely branchAlexander Monakov, Sep 8, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.