[RFC PATCH 07/10] linear-assignment.c: convert a macro to a "static inline" function
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Dec 9, 2021, 19:19 UTC
- Message-ID
- <RFC-patch-07.10-a82771413f7-20211209T191653Z-avarab@gmail.com>
- In-Reply-To
- <RFC-cover-00.10-00000000000-20211209T191653Z-avarab@gmail.com>
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 --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,
-- 2.34.1.930.g0f9292b224d