diff src/macros.h @ 25477:a8f526c9b172 v8.2.3275

patch 8.2.3275: optimizer can use hints about ga_grow() normally succeeding Commit: https://github.com/vim/vim/commit/35578168becd1e11973bec413f2078a4bf81ba6b Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 2 19:10:38 2021 +0200 patch 8.2.3275: optimizer can use hints about ga_grow() normally succeeding Problem: Optimizer can use hints about ga_grow() normally succeeding. Solution: Use GA_GROW_FAILS() and GA_GROW_OK() in several places. (Dominique Pell?, issue #8635)
author Bram Moolenaar <Bram@vim.org>
date Mon, 02 Aug 2021 19:15:03 +0200
parents 7334bf933510
children 41a940219183
line wrap: on
line diff
--- a/src/macros.h
+++ b/src/macros.h
@@ -387,8 +387,10 @@
 // Inline the condition for performance.
 #define CHECK_LIST_MATERIALIZE(l) if ((l)->lv_first == &range_list_item) range_list_materialize(l)
 
-// Inlined version of ga_grow().  Especially useful if "n" is a constant.
-#define GA_GROW(gap, n) (((gap)->ga_maxlen - (gap)->ga_len < n) ? ga_grow_inner((gap), (n)) : OK)
+// Inlined version of ga_grow() with optimized condition that it fails.
+#define GA_GROW_FAILS(gap, n) unlikely((((gap)->ga_maxlen - (gap)->ga_len < n) ? ga_grow_inner((gap), (n)) : OK) == FAIL)
+// Inlined version of ga_grow() with optimized condition that it succeeds.
+#define GA_GROW_OK(gap, n) likely((((gap)->ga_maxlen - (gap)->ga_len < n) ? ga_grow_inner((gap), (n)) : OK) == OK)
 
 #ifndef MIN
 # define MIN(a, b) ((a) < (b) ? (a) : (b))