diff mbox series

[RFC,07/10] linear-assignment.c: convert a macro to a "static inline" function

Message ID RFC-patch-07.10-a82771413f7-20211209T191653Z-avarab@gmail.com (mailing list archive)
State Superseded
Headers show
Series range-diff: fix segfault due to integer overflow | expand

Commit Message

Ævar Arnfjörð Bjarmason Dec. 9, 2021, 7:19 p.m. UTC
Change the COST() macro to be a "static inline" function. On GCC this
makes no difference in performance, but this improves the readability
of the function. In a subsequent commit we'll make use of this to
extend this function with overflow detection.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 linear-assignment.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/linear-assignment.c b/linear-assignment.c
index 1f8329701a0..e9cec16132a 100644
--- a/linear-assignment.c
+++ b/linear-assignment.c
@@ -6,7 +6,16 @@ 
 #include "cache.h"
 #include "linear-assignment.h"
 
-#define COST(column, row) cost[(column) + column_count * (row)]
+static inline int cost_index(int *cost, int a, int b, int c)
+{
+	int r;
+
+	r = b + a * c;
+
+	return r;
+}
+
+#define COST(column, row) cost[cost_index(cost, column_count, column, row)]
 
 static void columns_reduction(size_t column_count, size_t row_count,
 			      int *cost,