Re: [RFC PATCH v2 2/5] linear-assignment.c: split up compute_assignment() function
- From
Jeff King <peff@peff.net>
- Date
- Dec 14, 2021, 13:39 UTC
- Message-ID
- <YbiemFN4F0ebr796@coredump.intra.peff.net>
- In-Reply-To
- <RFC-patch-v2-2.5-2233872545e-20211210T122901Z-avarab@gmail.com>
On Fri, Dec 10, 2021 at 01:30:39PM +0100, Ævar Arnfjörð Bjarmason wrote:
> Split up the the long compute_assignment() function to make it easier > to reason about, particularly when it comes to what variables are used > later, and which aren't.
OK, this refactor seems reasonable. I don't know enough about the linear-assignment algorithm to know whether the names you've picked are meaningful.
Show 11 quoted lines
> +void compute_assignment(int column_count, int row_count,
> + int *cost,
> + int *column2row, int *row2column)
> +{
> + int *v;
> + int *free_row, free_count = 0, saved_free_count;
> +
> + assert(column_count > 1);
> + memset(column2row, -1, sizeof(int) * column_count);
> + memset(row2column, -1, sizeof(int) * row_count);
> + ALLOC_ARRAY(v, column_count);So this is the code where we would have kept the column_count check and zero'd column2row and row2column, had we not moved it in the previous commit. I actually think it would fit fine here in the refactored compute_assignment() if you had left it.
-Peff